Sha256: cb7b82e8f6302e1201f7ba8e21bde1ce46301631420eba8e9c0ac6c252549314
Contents?: true
Size: 1.21 KB
Versions: 4
Compression:
Stored size: 1.21 KB
Contents
class SimpleContentManagement::SimplePage < ActiveRecord::Base has_many :simple_routes, conditions: { is_deleted: false }, class_name: "SimpleContentManagement::SimpleRoute" attr_accessible :name, :title, :content_html, :simple_routes_list scope :active, where(is_deleted: false) def simple_routes_list path_names.join "," end def simple_routes_list=(routes_list) path_names = routes_list.split "," # destroy routes that are no longer required self.simple_routes.each do |simple_route| simple_route.destroy unless path_names.include? simple_route.path end # ensure any existing routes are set active to the current page. SimpleContentManagement::SimpleRoute.where(path: path_names).each do |simple_route| simple_route.simple_page = self simple_route.is_deleted = false simple_route.save path_names.delete simple_route.path end # create the remaining routes path_names.each do |path_name| self.simple_routes.build path: path_name end end def path_names simple_routes.active.pluck("path") end def has_simple_menu_item? SimpleContentManagement::SimpleMenuItem.where(uri: path_names.map{ |path| "/#{path}.html" }).any? end def destroy update_attribute :is_deleted, true end end
Version data entries
4 entries across 4 versions & 1 rubygems