app/models/effective/page.rb in effective_pages-3.1.0 vs app/models/effective/page.rb in effective_pages-3.1.1

- old
+ new

@@ -57,11 +57,11 @@ validates :meta_description, presence: true, length: { maximum: 150 } validates :layout, presence: true validates :template, presence: true - validates :menu_name, if: -> { menu? && EffectivePages.menus.present? }, presence: true + validates :menu_name, if: -> { menu_root? && EffectivePages.menus.present? }, presence: true # validates :menu_position, if: -> { menu? }, # presence: true, uniqueness: { scope: [:menu_name, :menu_parent_id] } scope :deep, -> { includes(:menu_parent, menu_children: :menu_parent) } @@ -70,11 +70,11 @@ scope :published, -> { where(draft: false) } scope :sorted, -> { order(:title) } scope :on_menu, -> { where(menu: true) } scope :except_home, -> { where.not(title: 'Home') } - scope :menuable, -> { where(menu: true).order(:menu_position) } + scope :menuable, -> { published.where(menu: true).order(:menu_position) } scope :menu_deep, -> { includes(:menu_parent, :menu_children) } scope :for_menu, -> (name) { menuable.where(menu_name: name) } scope :for_menu_root, -> (name) { for_menu(name).menu_deep.root_level } scope :root_level, -> { where(menu_parent_id: nil) } @@ -112,11 +112,29 @@ def duplicate! duplicate.tap { |page| page.save! } end + # When true, this should not appear in sitemap.xml and should return 404 if visited + def menu_root_with_children? + menu_root? && menu_parent? + end + + # This is for the form def menu_root_level - menu? && menu_parent.blank? + menu_root? + end + + def menu_root? + menu? && menu_parent_id.blank? + end + + def menu_parent? + menu? && menu_children.to_a.present? + end + + def menu_child? + menu? && menu_parent_id.present? end end end