Module: Redmine::Acts::Attachable::ClassMethods

Defined in:
lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_attachable(options = {}) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb', line 26

def acts_as_attachable(options = {})
  cattr_accessor :attachable_options
  self.attachable_options = {}
  attachable_options[:view_permission] = options.delete(:view_permission) || "view_#{self.name.pluralize.underscore}".to_sym
  attachable_options[:edit_permission] = options.delete(:edit_permission) || "edit_#{self.name.pluralize.underscore}".to_sym
  attachable_options[:delete_permission] = options.delete(:delete_permission) || "edit_#{self.name.pluralize.underscore}".to_sym

  has_many :attachments, lambda {order("#{Attachment.table_name}.created_on ASC, #{Attachment.table_name}.id ASC")},
                         options.merge(:as => :container, :dependent => :destroy, :inverse_of => :container)
  send :include, Redmine::Acts::Attachable::InstanceMethods
  before_save :attach_saved_attachments
end