Sha256: c450af97b939324eb5991748bda4d4a964c0c0287d2c94f569185089a1bc2438

Contents?: true

Size: 686 Bytes

Versions: 15

Compression:

Stored size: 686 Bytes

Contents

class Menu < ActiveRecord::Base
  has_many :menu_items, :order=>"order_by"


  def top_level_items
    r = []
    self.menu_items.each do |item|
      r << item if item.parent_id = 0
    end
    return r
  end

  def add_page(page, name=nil, parent_id = 0)
    mi = MenuItem.new
    mi.parent_id = parent_id
    mi.name = name || page.title
    mi.link_url = page.full_path
    mi.title = page.title
    mi.menu_id = self.id
    mi.order_by = self.menu_items.count + 1
    mi.system_id = self.system_id
    mi.save
  end

  def flush
    Rails.cache.delete(Menu.cache_key(self.system_id, self.name))
  end

  def Menu.cache_key(sid, name)
    "_menu_#{sid}_#{name.downcase}"
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
kit_cms-2.3.22 app/models/menu.rb
kit_cms-2.3.20 app/models/menu.rb
kit_cms-2.3.19 app/models/menu.rb
kit_cms-2.3.18 app/models/menu.rb
kit_cms-2.3.17 app/models/menu.rb
kit_cms-2.3.16 app/models/menu.rb
kit_cms-2.3.15 app/models/menu.rb
kit_cms-2.3.14 app/models/menu.rb
kit_cms-2.3.13 app/models/menu.rb
kit_cms-2.3.11 app/models/menu.rb
kit_cms-2.3.10 app/models/menu.rb
kit_cms-2.3.9 app/models/menu.rb
kit_cms-2.3.8 app/models/menu.rb
kit_cms-2.3.7 app/models/menu.rb
kit_cms-2.3.6 app/models/menu.rb