Sha256: f82c6b15529ba50d02e39847653bc916db6327aee5026f0395eb89300a0c8931
Contents?: true
Size: 1.23 KB
Versions: 5
Compression:
Stored size: 1.23 KB
Contents
class MenuLink < ActiveRecord::Base translates :title, :url, :summary acts_as_tree :order => 'position' accepts_nested_attributes_for :children, :allow_destroy => true validates :title, :presence => true scope :actives, :conditions => { :active => true } belongs_to :menu belongs_to :target, :polymorphic => true def kind read_attribute(:type) end def kind=(kind) write_attribute(:type, kind) end def clone menu_link = super menu_link.children = self.children.collect(&:clone) return menu_link end def url_with_target url_attribute = url_without_target if url_attribute.nil? || url_attribute.blank? target_id ? target : '#' else url_attribute end end alias_method_chain :url, :target def url_and_children_urls (self.children.map(&:url) + [self.url]) end def url_and_parent_urls return [self.url] unless self.parent (self.parent.url_and_parent_urls + [self.url]) end def url_match?(url_pattern='') case url_pattern when String url_and_children_urls.include?("/#{CGI::unescape(url_pattern)}".gsub(/\/+/, '/')) when Array url_and_children_urls.include?("/#{url_pattern.last}") else false end end end
Version data entries
5 entries across 5 versions & 1 rubygems