13: def belongs_to_attachment(options={})
14: @belongs_to_attachment = true
15: include InstanceMethods
16: before_validation :process_attachment
17: before_save :update_attachment_if_changed
18: after_save :clear_attachment_ivars
19: belongs_to :attachment, :dependent => :destroy
20:
21: validates_each :attachment_file do |record, attr, value|
22: if record.attachment && !record.attachment.valid?
23: record.attachment.errors.each do |err_field, err_value|
24: if err_field.to_sym == :file_path
25: record.errors.add(:attachment_file_path, err_value)
26: else
27: record.errors.add(:attachment_file, err_value)
28: end
29: end
30: end
31: end
32: end