Class: Compony::Components::WithForm
- Inherits:
-
Compony::Component
- Object
- Compony::Component
- Compony::Components::WithForm
- Defined in:
- lib/compony/components/with_form.rb
Overview
This component is destined to take a sub-component that is a form component.
It can be called via :get or via submit_verb depending on whether its form should be shown or submitted.
Instance Attribute Summary
Attributes inherited from Compony::Component
#comp_opts, #content_blocks, #parent_comp
Instance Method Summary collapse
-
#form_cancancan_action(new_form_cancancan_action = :missing) ⇒ Object
DSL method Sets and gets the form's cancancan action (for cancancan's accessible_attributes).
-
#form_comp ⇒ Object
Returns an instance of the form component responsible for rendering the form.
-
#form_comp_class(new_form_comp_class = nil) ⇒ Object
DSL method Overrides the form comp class that is instanciated to render the form.
-
#initialize ⇒ WithForm
constructor
A new instance of WithForm.
-
#submit_path(&new_submit_path_block) ⇒ Object
DSL method Overrides the submit path which would otherwise default to this component This takes a block that will be called and given a controller.
-
#submit_verb(new_submit_verb = nil) ⇒ Object
DSL method Sets or returns the previously set submit verb.
Methods inherited from Compony::Component
#action, #before_render, comp_cst, comp_name, #content, family_cst, family_name, #id, #id_path, #id_path_hash, #inspect, #param_name, #path, #remove_content, #remove_content!, #render, #render_actions, #resourceful?, #root_comp, #root_comp?, setup, #skip_action, #sub_comp
Constructor Details
Instance Method Details
#form_cancancan_action(new_form_cancancan_action = :missing) ⇒ Object
DSL method Sets and gets the form's cancancan action (for cancancan's accessible_attributes)
45 46 47 48 49 50 |
# File 'lib/compony/components/with_form.rb', line 45 def form_cancancan_action(new_form_cancancan_action = :missing) if new_form_cancancan_action != :missing @form_cancancan_action = new_form_cancancan_action end return @form_cancancan_action end |
#form_comp ⇒ Object
Returns an instance of the form component responsible for rendering the form. Feel free to override this in subclasses.
15 16 17 18 19 20 21 22 23 |
# File 'lib/compony/components/with_form.rb', line 15 def form_comp @form_comp ||= (form_comp_class || Compony.comp_class_for!(:form, family_cst)).new( self, submit_verb:, # If applicable, Rails adds the route keys automatically, thus, e.g. :id does not need to be passed here, as it comes from the request. submit_path: @submit_path_block, cancancan_action: form_cancancan_action ) end |
#form_comp_class(new_form_comp_class = nil) ⇒ Object
DSL method Overrides the form comp class that is instanciated to render the form
39 40 41 |
# File 'lib/compony/components/with_form.rb', line 39 def form_comp_class(new_form_comp_class = nil) @form_comp_class ||= new_form_comp_class end |
#submit_path(&new_submit_path_block) ⇒ Object
DSL method Overrides the submit path which would otherwise default to this component This takes a block that will be called and given a controller
55 56 57 |
# File 'lib/compony/components/with_form.rb', line 55 def submit_path(&new_submit_path_block) @submit_path_block = new_submit_path_block end |
#submit_verb(new_submit_verb = nil) ⇒ Object
DSL method Sets or returns the previously set submit verb
27 28 29 30 31 32 33 34 35 |
# File 'lib/compony/components/with_form.rb', line 27 def submit_verb(new_submit_verb = nil) if new_submit_verb.present? new_submit_verb = new_submit_verb.to_sym available_verbs = ComponentMixins::Default::Standalone::VerbDsl::AVAILABLE_VERBS fail "Unknown HTTP verb #{new_submit_verb.inspect}, use one of #{available_verbs.inspect}" unless available_verbs.include?(new_submit_verb) @submit_verb = new_submit_verb end return @submit_verb || fail("WithForm component #{self} is missing a call to `submit_verb`.") end |