Class: TemplateForm::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
lib/template_form/form_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFormBuilder



19
20
21
22
23
24
# File 'lib/template_form/form_builder.rb', line 19

def initialize(...)
  super
  parent_options = options[:parent_builder]&.options
  @form_type = options[:form_type] || parent_options&.dig(:form_type) || TemplateForm.form_type
  @view = options[:view] || parent_options&.dig(:view)
end

Instance Attribute Details

#form_typeObject (readonly)

Returns the value of attribute form_type.



17
18
19
# File 'lib/template_form/form_builder.rb', line 17

def form_type
  @form_type
end

Instance Method Details

#hidden(attribute_name, options = {}) ⇒ Object



39
40
41
# File 'lib/template_form/form_builder.rb', line 39

def hidden(attribute_name, options = {})
  hidden_field attribute_name, options
end

#input(attribute_name, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/template_form/form_builder.rb', line 26

def input(attribute_name, options = {})
  attribute_type = options.delete(:as) ||
    (@object.respond_to?(:type_for_attribute) && @object.type_for_attribute(attribute_name).type) ||
    :string

  options[:type] ||= 'password' if attribute_name.match(/password/)

  options.merge! view: @view if @view

  input_for(attribute_type).new(self, attribute_name, options).render
end