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



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb', line 52

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, as: :container, dependent: :destroy, inverse_of: :container
  send :include, Redmine::Acts::Attachable::InstanceMethods
  before_save :attach_saved_attachments
  after_rollback :detach_saved_attachments
  validate :warn_about_failed_attachments
end