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

Returns a new instance of FormBuilder.



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

def initialize(*)
  super
  # Do not remove `:form_type` from `options`.  It has to stay so
  # when `fields_for()` instantiates a new form builder for each
  # associated record, the second and subsequent ones have the
  # correct form type.
  @form_type = options[:form_type] || TemplateForm.form_type
  @view = options[:view]
end

Instance Attribute Details

#form_typeObject (readonly)

Returns the value of attribute form_type.



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

def form_type
  @form_type
end

Instance Method Details

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



41
42
43
# File 'lib/template_form/form_builder.rb', line 41

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

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



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

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