Module: AwesomeForm::Methods::Naming
- Included in:
- FormBuilder
- Defined in:
- lib/awesome_form/methods/naming.rb
Instance Method Summary collapse
- #association_name(attribute_name) ⇒ Object
- #collection_name(attribute_name, index = nil) ⇒ Object
- #input_id(attribute_name) ⇒ Object
- #input_name(attribute_name) ⇒ Object
Instance Method Details
#association_name(attribute_name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/awesome_form/methods/naming.rb', line 13 def association_name(attribute_name) reflection = association_for_attribute(attribute_name) case reflection.macro when :belongs_to then input_name "#{attribute_name}_id" when :has_many then collection_name "#{attribute_name.to_s.singularize}_ids" when :has_one raise "Can't create the association name for a :has_one association" else raise "Unknown association #{reflection.macro}" end end |
#collection_name(attribute_name, index = nil) ⇒ Object
9 10 11 |
# File 'lib/awesome_form/methods/naming.rb', line 9 def collection_name(attribute_name, index=nil) "#{object_name}[#{attribute_name}][#{index}]" end |
#input_id(attribute_name) ⇒ Object
26 27 28 |
# File 'lib/awesome_form/methods/naming.rb', line 26 def input_id(attribute_name) "#{object_name.underscore}_#{attribute_name}_input" end |
#input_name(attribute_name) ⇒ Object
5 6 7 |
# File 'lib/awesome_form/methods/naming.rb', line 5 def input_name(attribute_name) "#{object_name}[#{attribute_name}]" end |