Sha256: 9c567a2dcb89a8c9f42dcdb4ac310d3d07e9d774f48f0bc37f26f7d14333bb46
Contents?: true
Size: 1.4 KB
Versions: 6
Compression:
Stored size: 1.4 KB
Contents
class Cms::Block < ActiveRecord::Base ComfortableMexicanSofa.establish_connection(self) set_table_name :cms_blocks # -- Relationships -------------------------------------------------------- belongs_to :page has_many :files, :autosave => true, :dependent => :destroy # -- Callbacks ------------------------------------------------------------ before_save :prepare_files # -- Validations ---------------------------------------------------------- validates :label, :presence => true, :uniqueness => { :scope => :page_id } # -- Instance Methods ----------------------------------------------------- # Tag object that is using this block def tag page.tags(true).detect{|t| t.is_cms_block? && t.label == label} end protected def prepare_files temp_files = [self.content].flatten.select do |f| %w(ActionDispatch::Http::UploadedFile Rack::Test::UploadedFile).member?(f.class.name) end # only accepting one file if it's PageFile. PageFiles will take all single_file = self.tag.is_a?(ComfortableMexicanSofa::Tag::PageFile) temp_files = [temp_files.first].compact if single_file temp_files.each do |file| self.files.collect{|f| f.mark_for_destruction } if single_file self.files.build(:site => self.page.site, :file => file) end self.content = nil unless self.content.is_a?(String) end end
Version data entries
6 entries across 6 versions & 1 rubygems