Module: Cms::Behaviors::Attaching::MacroMethods
- Defined in:
- lib/cms/behaviors/attaching.rb
Instance Method Summary collapse
-
#allow_attachments ⇒ Object
Adds additional behavior to a model which allows it to have attachments.
Instance Method Details
#allow_attachments ⇒ Object
Adds additional behavior to a model which allows it to have attachments. Typically, clients will not need to call this directly. Enabling attachments is normally done via:
acts_as_content_block :allow_attachments => false
By default, blocks can have attachments.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cms/behaviors/attaching.rb', line 71 def extend ClassMethods extend Validations include InstanceMethods # Allows a block to be associated with a list of uploaded attachments (done via AJAX) attr_accessor :attachment_id_list, :attachments_changed Cms::Attachment.definitions[self.name] = {} has_many :attachments, :as => :attachable, :dependent => :destroy, :class_name => 'Cms::Attachment', :autosave => false accepts_nested_attributes_for :attachments, :allow_destroy => true, # New attachments must have an uploaded file :reject_if => lambda { |a| a[:data].blank? && a[:id].blank? } attr_accessible :attachments_attributes, :attachment_id_list, :attachments_changed validates_associated :attachments before_validation :initialize_attachments, :check_for_updated_attachments after_validation :filter_generic_attachment_errors before_create :associate_new_attachments before_save :ensure_status_matches_attachable after_save :save_associated_attachments end |