Sha256: 0ba5f9635430d3b082794144c7be86e1a6305201c3e97cd298e2b14c479cf483
Contents?: true
Size: 1.52 KB
Versions: 2
Compression:
Stored size: 1.52 KB
Contents
# encoding: UTF-8 module Ksk module Navigation extend ActiveSupport::Concern included do self.table_name = 'navigations' validates_uniqueness_of :slug validates_presence_of :static before_validation :static_setter default_scope :order => 'position ASC, created_at DESC' belongs_to :static belongs_to :navigation_type belongs_to :parent, :foreign_key => 'parent_id', :class_name => 'Navigation' has_many :children, :foreign_key => 'parent_id', :class_name => 'Navigation', :dependent => :delete_all scope :top_level, where(parent_id: 0) scope :not_hidden, where(hidden: false) before_save :set_slug, :set_link end def set_slug return if !slug.blank? write_attribute(:slug, title.to_url) end def static_setter write_attribute(:static_id, (self.static && self.static.id) || ::Static.all.first.id) end def set_link write_attribute(:link, get_link) end def get_link(x = '') a = '/'+slug+x if parent a = parent.get_link(a) end a end module ClassMethods def sort_items(ids) ids.each_pair do |i, id| find(id).update_attribute(:position, i.to_i) end end def show_bread_crum_desc(navi) a = [navi] if navi.parent a << show_bread_crum_desc(navi.parent) end a.flatten end def show_bread_crum(navi) show_bread_crum_desc(navi).reverse end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ksk-0.1.2 | lib/actives/navigation.rb |
ksk-0.1.1 | lib/actives/navigation.rb |