Class: TemplateForm::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- TemplateForm::FormBuilder
- Defined in:
- lib/template_form/form_builder.rb
Instance Attribute Summary collapse
-
#form_type ⇒ Object
readonly
Returns the value of attribute form_type.
Instance Method Summary collapse
- #hidden(attribute_name, options = {}) ⇒ Object
-
#initialize ⇒ FormBuilder
constructor
A new instance of FormBuilder.
- #input(attribute_name, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ FormBuilder
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 = [:form_type] || TemplateForm.form_type @view = [:view] end |
Instance Attribute Details
#form_type ⇒ Object (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, = {}) hidden_field attribute_name, 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, = {}) attribute_type = .delete(:as) || (@object.respond_to?(:type_for_attribute) && @object.type_for_attribute(attribute_name).type) || :string [:type] ||= 'password' if attribute_name.match(/password/) .merge! view: @view if @view input_for(attribute_type).new(self, attribute_name, ).render end |