Sha256: 3758024e52741e12ae6e73e8713c8178e8a6e83b25a11107e7c49c0749f6ab4d
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
module NoCms::Pages class Page < ActiveRecord::Base include Concerns::TranslationScopes scope :drafts, ->() { where_with_locale(draft: true) } scope :no_drafts, ->() { where_with_locale(draft: false) } acts_as_nested_set has_many :blocks, inverse_of: :page, class_name: 'NoCms::Pages::Block' accepts_nested_attributes_for :blocks, allow_destroy: true translates :title, :body, :slug, :path, :draft validates :title, :body, presence: true validates :slug, presence: { allow_blank: true } before_validation :set_slug_and_path after_move :rebuild_path def set_slug_and_path self.slug = title.parameterize if slug.nil? && !title.nil? self.rebuild_path if path.nil? end def rebuild_path self.update_attribute :path, "#{ancestors.map(&:path).join}/#{slug}" end def self.templates Dir[Rails.root.join('app', 'views', 'no_cms', 'pages', 'pages', '*.html.erb').to_s]. # We get all page templates map { |f| File.basename(f, '.html.erb') }.uniq.sort # And get their names end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nocms-pages-0.0.1 | app/models/no_cms/pages/page.rb |