Sha256: 0c4c9b4a1e5b63f5cd3e7d8d51d9babe8eff9cfbeca89cd06d67ef19083b9ff0
Contents?: true
Size: 1.17 KB
Versions: 23
Compression:
Stored size: 1.17 KB
Contents
module Brightcontent module PageCore extend ActiveSupport::Concern included do include TheSortableTree::Scopes has_attached_files Brightcontent.page_attachment_styles acts_as_nested_set validates_presence_of :name after_save :update_slug, :expire_path_cache after_move :update_slug, :expire_path_cache scope :visible, -> { where(arel_table[:hidden].eq false) } scope :hidden, -> { where(arel_table[:hidden].eq true) } default_scope { order(:lft) } end module ClassMethods def find_by_path(path) find_by(slug: sanitize_path(path)) end def find_by_path!(path) find_by!(slug: sanitize_path(path)) end def sanitize_path(path) path[1..-1] end end def homepage? lft == 1 end def path "/" + slug end def to_s name end private def update_slug update_column(:slug, slug_name.to_s) end def slug_name unless homepage? self_and_ancestors.map { |p| p.name.parameterize }.join("/") end end def expire_path_cache Pages::PathConstraint.expire end end end
Version data entries
23 entries across 23 versions & 1 rubygems