Class: BrainDamage::View::Input::PolymorphicSelect
- Inherits:
-
NestedOnHideable
- Object
- Templateable::Base
- Templateable::FieldTemplateable
- Base
- NestedOnHideable
- BrainDamage::View::Input::PolymorphicSelect
- Defined in:
- lib/generators/brain_damage/lib/views/inputs/polymorphic_select.rb
Instance Attribute Summary
Attributes inherited from Templateable::FieldTemplateable
Attributes inherited from Templateable::Base
#inner_html, #options, #template_file
Instance Method Summary collapse
-
#initialize(field, options) ⇒ PolymorphicSelect
constructor
A new instance of PolymorphicSelect.
- #object_select_name ⇒ Object
- #options_for_type ⇒ Object
- #type_select_name ⇒ Object
- #types_options ⇒ Object
Methods inherited from NestedOnHideable
#guard, #label_guard, #label_guard?
Methods inherited from Base
Methods inherited from Templateable::FieldTemplateable
#empty_haml_path, #label_guard?, #method_missing, #render, #show?, #show_label?
Methods inherited from Templateable::Base
#indent, #method_missing, #render, #render_erb_file, #render_erb_string, #render_template_file
Constructor Details
#initialize(field, options) ⇒ PolymorphicSelect
Returns a new instance of PolymorphicSelect.
8 9 10 11 |
# File 'lib/generators/brain_damage/lib/views/inputs/polymorphic_select.rb', line 8 def initialize(field, ) super @normalized_name = name.to_s.gsub('_id', '').gsub('_type', '') end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class BrainDamage::Templateable::FieldTemplateable
Instance Method Details
#object_select_name ⇒ Object
17 18 19 |
# File 'lib/generators/brain_damage/lib/views/inputs/polymorphic_select.rb', line 17 def object_select_name "#{@normalized_name}_id" end |
#options_for_type ⇒ Object
21 22 23 24 25 |
# File 'lib/generators/brain_damage/lib/views/inputs/polymorphic_select.rb', line 21 def @options[:options].map{ |option| "[cet('entities.#{option[:model].to_s.downcase}'), '#{option[:model].to_s}']" }.join ', ' end |
#type_select_name ⇒ Object
13 14 15 |
# File 'lib/generators/brain_damage/lib/views/inputs/polymorphic_select.rb', line 13 def type_select_name "#{@normalized_name}_type" end |
#types_options ⇒ Object
27 28 29 |
# File 'lib/generators/brain_damage/lib/views/inputs/polymorphic_select.rb', line 27 def @options[:options] end |