Module: Mongo::Model::AttachmentsHelper::ClassMethods

Defined in:
lib/kit/models/attachments_helper.rb

Instance Method Summary collapse

Instance Method Details

#mount_attachments(association_name, field_name, &block) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/kit/models/attachments_helper.rb', line 72

def mount_attachments association_name, field_name, &block
  define_method "#{association_name}_as_attachments" do
    get_attachments association_name, field_name
  end

  define_method "#{association_name}_as_attachments=" do |values|
    set_attachments association_name, field_name, values, &block
  end

  # we can't allow to destroy model with changed attachments because it's too complicated to support this case.
  # before_destroy{|o| raise "Can't destroy item with changed attachments!" if o.changes.include? association_name}
end