Sha256: cbb166e35dcd6fc13c6f0ab8ddb85213aaa43e36d0b2ba655ca46d8dee413b6b
Contents?: true
Size: 879 Bytes
Versions: 5
Compression:
Stored size: 879 Bytes
Contents
class Attachment < ActiveRecord::Base attr_accessible :attachable_id, :file, :name, :description, :position mount_uploader :file , AttachmentUploader validates_presence_of :file, :on => :create belongs_to :attachable, :polymorphic => true delegate :url, :to => :file def serializable_hash(options = nil) options ||= {} options[:methods] ||= [] options[:methods] << :url super(options) end def move(prev_pos,next_pos) self.insert_at(prev_pos) if prev_pos && prev_pos>self.position self.insert_at(next_pos) if next_pos && next_pos<self.position end protected before_save :update_file_attributes def update_file_attributes if file.present? && file_changed? self.content_type = file.file.content_type self.file_size = file.file.size self.original_filename = file.file.original_filename end end end
Version data entries
5 entries across 5 versions & 1 rubygems