class Image include Mongoid::Document include Mongoid::Timestamps field :html_id field :html_class field :in_css, :type => Boolean, :default => false field :in_html, :type => Boolean, :default => false field :name mount_uploader :file, ImageUploader # belongs_to :design # belongs_to :desktop_widget belongs_to :imgs, polymorphic: true before_save :set_name protected def set_name self.name = self.file_identifier end end