universal_table/app/models/column_entry_file.rb

37 lines
790 B
Ruby

class ColumnEntryFile
include Mongoid::Document
include Mongoid::Timestamps
mount_uploader :file, AssetUploader
field :file_title, localize: true
# field :description
field :download_count, type: Integer, default: 0
field :choose_lang, :type => Array, :default => I18n.available_locales.map{|l| l.to_s}
field :should_destroy, :type => Boolean
field :sort_number, :type => Integer
# default_scope asc(:sort_number)
def choose_lang_display(lang)
self.file.present? && self.choose_lang.include?(lang)
end
def get_file_title
_file_title = self.file_title
if _file_title.blank? && self.file.present?
_file_title = self[:file]
end
_file_title
end
def get_link
"/xhr/universal_table/download?file=#{self.id}"
end
belongs_to :column_entry, index: true
end