Module: Formtastic::Inputs::Base::Associations
- Included in:
- Formtastic::Inputs::Base
- Defined in:
- lib/formtastic/inputs/base/associations.rb
Instance Method Summary collapse
-
#association ⇒ Object
:belongs_to, etc.
- #association_primary_key ⇒ Object
- #belongs_to? ⇒ Boolean
- #reflection ⇒ Object
Instance Method Details
#association ⇒ Object
:belongs_to, etc
7 8 9 |
# File 'lib/formtastic/inputs/base/associations.rb', line 7 def association @association ||= reflection.macro if reflection end |
#association_primary_key ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/formtastic/inputs/base/associations.rb', line 19 def association_primary_key if association return reflection.[:foreign_key] unless reflection.[:foreign_key].blank? return reflection.foreign_key if reflection.respond_to?(:foreign_key) return :"#{method}_id" if belongs_to? return "#{method.to_s.singularize}_id".pluralize.to_sym else return method.to_s end end |
#belongs_to? ⇒ Boolean
15 16 17 |
# File 'lib/formtastic/inputs/base/associations.rb', line 15 def belongs_to? association == :belongs_to end |
#reflection ⇒ Object
11 12 13 |
# File 'lib/formtastic/inputs/base/associations.rb', line 11 def reflection @reflection ||= object.class.reflect_on_association(method) if object.class.respond_to?(:reflect_on_association) end |