app/models/alchemy/page.rb in alchemy_cms-2.2.rc3 vs app/models/alchemy/page.rb in alchemy_cms-2.2.rc6

- old
+ new

@@ -1,9 +1,30 @@ # encoding: UTF-8 module Alchemy class Page < ActiveRecord::Base + attr_accessible( + :do_not_sweep, + :language_code, + :language_id, + :language_root, + :layoutpage, + :meta_description, + :meta_keywords, + :name, + :page_layout, + :parent_id, + :public, + :restricted, + :robot_index, + :robot_follow, + :sitemap, + :title, + :urlname, + :visible + ) + RESERVED_URLNAMES = %w(admin messages) acts_as_nested_set(:dependent => :destroy) stampable @@ -11,21 +32,21 @@ has_many :cells, :dependent => :destroy has_many :elements, :dependent => :destroy, :order => :position has_and_belongs_to_many :to_be_sweeped_elements, :class_name => 'Alchemy::Element', :uniq => true, :join_table => 'alchemy_elements_alchemy_pages' belongs_to :language - validates_presence_of :name, :message => '^' + I18n.t("please enter a name") - validates_presence_of :page_layout, :message => '^' + I18n.t("Please choose a page layout."), :unless => :systempage? - validates_presence_of :parent_id, :message => '^' + I18n.t("No parent page was given."), :if => proc { Page.count > 1 } - validates_length_of :urlname, :minimum => 3, :too_short => I18n.t("urlname_to_short"), :if => :urlname_entered? - validates_uniqueness_of :urlname, :message => '^' + I18n.t("URL-Name already token"), :scope => [:language_id, :layoutpage], :if => :urlname_entered? - validates :urlname, :exclusion => {:in => RESERVED_URLNAMES, :message => '^' + I18n.t("This urlname is reserved.")} + validates_presence_of :name + validates_presence_of :page_layout, :unless => :systempage? + validates_presence_of :parent_id, :if => proc { Page.count > 1 } + validates_length_of :urlname, :minimum => 3, :if => :urlname_entered? + validates_uniqueness_of :urlname, :scope => [:language_id, :layoutpage], :if => :urlname_entered? + validates :urlname, :exclusion => {:in => RESERVED_URLNAMES} attr_accessor :do_not_autogenerate attr_accessor :do_not_sweep attr_accessor :do_not_validate_language - before_save :set_url_name, :unless => proc { |page| page.systempage? || page.redirects_to_external? } + before_validation :set_url_name, :unless => proc { |page| page.systempage? || page.redirects_to_external? } before_save :set_title, :unless => proc { |page| page.systempage? || page.redirects_to_external? || !page.title.blank? } before_save :set_language_code, :unless => :systempage? before_save :set_restrictions_to_child_pages, :if => proc { |page| !page.systempage? && page.restricted_changed? } before_save :inherit_restricted_status, :if => proc { |page| !page.systempage? && page.parent && page.parent.restricted? } after_create :autogenerate_elements, :unless => proc { |page| page.systempage? || page.do_not_autogenerate }