Sha256: c8b4d93c2efcfa73309a90d29fe402f4a4f03ca6d40ce20f82de674bb6874836

Contents?: true

Size: 1.17 KB

Versions: 15

Compression:

Stored size: 1.17 KB

Contents

class Cms::Snippet < ActiveRecord::Base
  
  ComfortableMexicanSofa.establish_connection(self)
  
  set_table_name :cms_snippets
  
  cms_is_categorized
  cms_is_mirrored
  cms_has_revisions_for :content
  
  # -- Relationships --------------------------------------------------------
  belongs_to :site
  
  # -- Callbacks ------------------------------------------------------------
  before_validation :assign_label
  after_save    :clear_cached_page_content
  after_destroy :clear_cached_page_content
  
  # -- Validations ----------------------------------------------------------
  validates :site_id,
    :presence   => true
  validates :label,
    :presence   => true
  validates :slug,
    :presence   => true,
    :uniqueness => { :scope => :site_id },
    :format     => { :with => /^\w[a-z0-9_-]*$/i }
  
protected
  
  def assign_label
    self.label = self.label.blank?? self.slug.try(:titleize) : self.label
  end
  
  # Note: This might be slow. We have no idea where the snippet is used, so
  # gotta reload every single page. Kinda sucks, but might be ok unless there
  # are hundreds of pages.
  def clear_cached_page_content
    site.pages.all.each{ |page| page.save }
  end
  
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.4.22 app/models/cms/snippet.rb
comfortable_mexican_sofa-1.4.21 app/models/cms/snippet.rb
comfortable_mexican_sofa-1.4.20 app/models/cms/snippet.rb
comfortable_mexican_sofa-1.4.19 app/models/cms/snippet.rb
comfortable_mexican_sofa-1.4.18 app/models/cms/snippet.rb
comfortable_mexican_sofa-1.4.17 app/models/cms/snippet.rb
comfortable_mexican_sofa-1.4.16 app/models/cms/snippet.rb
comfortable_mexican_sofa-1.4.15 app/models/cms/snippet.rb
comfortable_mexican_sofa-1.4.14 app/models/cms/snippet.rb
comfortable_mexican_sofa-1.4.13 app/models/cms/snippet.rb
comfortable_mexican_sofa-1.4.12 app/models/cms/snippet.rb
comfortable_mexican_sofa-1.4.11 app/models/cms/snippet.rb
comfortable_mexican_sofa-1.4.10 app/models/cms/snippet.rb
comfortable_mexican_sofa-1.4.9 app/models/cms/snippet.rb
comfortable_mexican_sofa-1.4.8 app/models/cms/snippet.rb