Sha256: d2284bf1143e3868fb6224c99ba31ab9398cbbef292945324f29c3cbbfbf5203
Contents?: true
Size: 1.3 KB
Versions: 19
Compression:
Stored size: 1.3 KB
Contents
class Comfy::Cms::Snippet < ActiveRecord::Base self.table_name = 'comfy_cms_snippets' cms_is_categorized cms_is_mirrored cms_has_revisions_for :content # -- Relationships -------------------------------------------------------- belongs_to :site # -- Callbacks ------------------------------------------------------------ before_validation :assign_label before_create :assign_position after_save :clear_page_content_cache after_destroy :clear_page_content_cache # -- Validations ---------------------------------------------------------- validates :site_id, :presence => true validates :label, :presence => true validates :identifier, :presence => true, :uniqueness => { :scope => :site_id }, :format => { :with => /\A\w[\/a-z0-9_-]*\z/i } # -- Scopes --------------------------------------------------------------- default_scope -> { order('comfy_cms_snippets.position') } protected def assign_label self.label = self.label.blank?? self.identifier.try(:titleize) : self.label end def clear_page_content_cache Comfy::Cms::Page.where(:id => site.pages.pluck(:id)).update_all(:content_cache => nil) end def assign_position max = self.site.snippets.maximum(:position) self.position = max ? max + 1 : 0 end end
Version data entries
19 entries across 19 versions & 1 rubygems