Module: Cms::Behaviors::Attaching::MacroMethods

Defined in:
lib/cms/behaviors/attaching.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to_attachment(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cms/behaviors/attaching.rb', line 13

def belongs_to_attachment(options={})
  @belongs_to_attachment = true
  include InstanceMethods
  before_validation :process_attachment  
  before_save :update_attachment_if_changed
  after_save :clear_attachment_ivars
  belongs_to :attachment, :dependent => :destroy 
  
  validates_each :attachment_file do |record, attr, value|
    if record.attachment && !record.attachment.valid?
      record.attachment.errors.each do |err_field, err_value|
        if err_field.to_sym == :file_path
          record.errors.add(:attachment_file_path, err_value)
        else  
          record.errors.add(:attachment_file, err_value)
        end
      end      
    end
  end       
end

#belongs_to_attachment?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/cms/behaviors/attaching.rb', line 10

def belongs_to_attachment?
  !!@belongs_to_attachment
end