Class: VCFB::Component::Form

Inherits:
Base
  • Object
show all
Defined in:
lib/vcfb/component/form.rb

Instance Method Summary collapse

Methods inherited from Base

#collection_check_boxes, #collection_radio_buttons

Constructor Details

#initialize(model: nil, scope: nil, url: nil, format: nil, **options) ⇒ Form

Returns a new instance of Form.



4
5
6
7
8
9
10
11
12
# File 'lib/vcfb/component/form.rb', line 4

def initialize(model: nil, scope: nil, url: nil, format: nil, **options)
  run_callbacks :initialize do
    @model = model
    @scope = scope
    @url = url
    @format = format
    @options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(options) : options
  end
end

Instance Method Details

#form_tag(options = {}, &block) ⇒ Object

Because we’ve overridden the #content and #get_slot methods below to support yielding the form, we need to save the component to our custom form builder to support rendering slots in the form components.



17
18
19
20
21
22
23
# File 'lib/vcfb/component/form.rb', line 17

def form_tag(options = {}, &block)
  form_with(model: @model, scope: @scope, url: @url, format: @format, **options) do |form|
    form.form_component = self if form.respond_to?(:form_component=)
    @form = form
    block&.call(@form)
  end
end