Class: AdminAssistant::MultiFormView::Builder::SubFormBuilder
- Inherits:
-
Object
- Object
- AdminAssistant::MultiFormView::Builder::SubFormBuilder
- Defined in:
- lib/admin_assistant/form_view.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#initialize(object_name, object, template, options, proc, position) ⇒ SubFormBuilder
constructor
A new instance of SubFormBuilder.
- #method_missing(meth, *args, &block) ⇒ Object
- #my_field_helpers ⇒ Object
- #objectify_options(options) ⇒ Object
- #select(method, choices, options = {}, html_options = {}) ⇒ Object
Constructor Details
#initialize(object_name, object, template, options, proc, position) ⇒ SubFormBuilder
Returns a new instance of SubFormBuilder.
125 126 127 128 129 130 |
# File 'lib/admin_assistant/form_view.rb', line 125 def initialize(object_name, object, template, , proc, position) @object_name, @object, @template, @options, @proc = object_name, object, template, , proc @default_options = @options ? @options.slice(:index) : {} @prefix = ('a'..'z').to_a[position] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/admin_assistant/form_view.rb', line 132 def method_missing(meth, *args, &block) if my_field_helpers.include?(meth.to_s) method = args.shift = args.shift || {} @template.send( meth, "#{@object_name}[#{@prefix}]", method, () ) else super end end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
123 124 125 |
# File 'lib/admin_assistant/form_view.rb', line 123 def object @object end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
123 124 125 |
# File 'lib/admin_assistant/form_view.rb', line 123 def prefix @prefix end |
Instance Method Details
#my_field_helpers ⇒ Object
147 148 149 150 |
# File 'lib/admin_assistant/form_view.rb', line 147 def my_field_helpers ::ActionView::Helpers::FormBuilder.field_helpers - %w(label check_box radio_button fields_for) + ['datetime_select'] end |
#objectify_options(options) ⇒ Object
152 153 154 |
# File 'lib/admin_assistant/form_view.rb', line 152 def () @default_options.merge(.merge(:object => @object)) end |
#select(method, choices, options = {}, html_options = {}) ⇒ Object
156 157 158 159 160 161 |
# File 'lib/admin_assistant/form_view.rb', line 156 def select(method, choices, = {}, = {}) @template.select( "#{@object_name}[#{@prefix}]", method, choices, (), @default_options.merge() ) end |