Module: Formtastic::Inputs::Base::Associations

Included in:
Formtastic::Inputs::Base
Defined in:
lib/formtastic/inputs/base/associations.rb

Instance Method Summary collapse

Instance Method Details

#associationObject

: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_keyObject



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.options[:foreign_key] unless reflection.options[: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

Returns:

  • (Boolean)


15
16
17
# File 'lib/formtastic/inputs/base/associations.rb', line 15

def belongs_to?
  association == :belongs_to
end

#reflectionObject



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