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
Instance Method Summary collapse
-
#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.
-
#submit_verb(new_submit_verb = nil) ⇒ Object
DSL method Sets or returns the previously set submit verb.
Methods inherited from Compony::Component
#action, #add_content, #before_render, #check_config!, #comp_class_for, #comp_class_for!, #comp_cst, #comp_name, #content, #family_cst, #family_name, #id, #initialize, #inspect, #param_name, #path, #path_hash, #render, #render_actions, #resourceful?, #root_comp, #root_comp?, setup, #skip_action, #sub_comp
Constructor Details
This class inherits a constructor from Compony::Component
Instance Method Details
#form_comp ⇒ Object
Returns an instance of the form component responsible for rendering the form. Feel free to override this in subclasses.
9 10 11 12 13 14 15 16 |
# File 'lib/compony/components/with_form.rb', line 9 def form_comp @form_comp ||= (form_comp_class || 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: ->(controller) { controller.helpers.send("#{Compony.path_helper_name(comp_name, family_name)}_path") } ) end |
#form_comp_class(new_form_comp_class = nil) ⇒ Object
DSL method Overrides the form comp class that is instanciated to render the form
32 33 34 |
# File 'lib/compony/components/with_form.rb', line 32 def form_comp_class(new_form_comp_class = nil) @form_comp_class ||= new_form_comp_class end |
#submit_verb(new_submit_verb = nil) ⇒ Object
DSL method Sets or returns the previously set submit verb
20 21 22 23 24 25 26 27 28 |
# File 'lib/compony/components/with_form.rb', line 20 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 |