Module: Damselfly::ClassMethods
- Defined in:
- lib/damselfly.rb
Instance Method Summary collapse
Instance Method Details
#has_many_attached(name) ⇒ Object
22 23 24 25 |
# File 'lib/damselfly.rb', line 22 def has_many_attached(name) has_many name, as: :attachable, class_name: "Damselfly::Attachment", conditions: ["#{Damselfly::Attachment.table_name}.association_name = ?", name], before_add: lambda { |attachable,| .association_name = name } accepts_nested_attributes_for name end |
#has_one_attached(name) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/damselfly.rb', line 11 def has_one_attached(name) has_one name, as: :attachable, class_name: "Damselfly::Attachment", conditions: ["#{Damselfly::Attachment.table_name}.association_name = ?", name] accepts_nested_attributes_for name class_eval do define_method("build_#{name}") do |args, opts| super(args.merge!(association_name: name), opts) end end end |