Sha256: bc37444c7d0a981e6d6ac2531f42bb3cb689b4efeb6982ba3ece855153168a41

Contents?: true

Size: 1007 Bytes

Versions: 2

Compression:

Stored size: 1007 Bytes

Contents

class Cms::File < ActiveRecord::Base
  
  if ComfortableMexicanSofa.config.database_config && !Rails.env.test?
    establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}"
  end
    
  set_table_name :cms_files
  
  cms_is_categorized
  
  # -- AR Extensions --------------------------------------------------------
  has_attached_file :file, ComfortableMexicanSofa.config.upload_file_options
  
  # -- Relationships --------------------------------------------------------
  belongs_to :site
  
  # -- Validations ----------------------------------------------------------
  validates :site_id, :presence => true
  validates_attachment_presence :file
  
  validates_uniqueness_of :file_file_name,
    :scope => :site_id
  
  # -- Callbacks ------------------------------------------------------------
  before_save :assign_label
  
protected
  
  def assign_label
    self.label = self.label.blank?? self.file_file_name.gsub(/\.[^\.]*?$/, '').titleize : self.label
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.4.7 app/models/cms/file.rb
comfortable_mexican_sofa-1.4.6 app/models/cms/file.rb