Class: Menu
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Menu
- Defined in:
- app/models/menu.rb
Overview
this is needed for now to make mass assignment security compatible with the translation of globalize3 Globalize::ActiveRecord::Translation.class_eval do
attr_accessible :locale
end
Instance Method Summary collapse
- #children ⇒ Object
- #has_children? ⇒ Boolean
- #has_parent? ⇒ Boolean
- #has_siblings? ⇒ Boolean
- #orphan? ⇒ Boolean
- #parent ⇒ Object
-
#parent_menu_name ⇒ Object
autocomplete related instance methods.
- #parent_menu_name=(name) ⇒ Object
- #self_and_siblings ⇒ Object
- #siblings ⇒ Object
- #to_param ⇒ Object
Instance Method Details
#children ⇒ Object
32 33 34 |
# File 'app/models/menu.rb', line 32 def children Menu.with_parent_id(id) end |
#has_children? ⇒ Boolean
28 29 30 |
# File 'app/models/menu.rb', line 28 def has_children? Menu.with_parent_id(id).count >= 1 end |
#has_parent? ⇒ Boolean
36 37 38 |
# File 'app/models/menu.rb', line 36 def has_parent? !parent_id.nil? end |
#has_siblings? ⇒ Boolean
44 45 46 |
# File 'app/models/menu.rb', line 44 def has_siblings? Menu.with_parent_id(parent_id).count >= 1 end |
#orphan? ⇒ Boolean
24 25 26 |
# File 'app/models/menu.rb', line 24 def orphan? parent_id == nil end |
#parent ⇒ Object
40 41 42 |
# File 'app/models/menu.rb', line 40 def parent Menu.find(parent_id) end |
#parent_menu_name ⇒ Object
autocomplete related instance methods
61 62 63 |
# File 'app/models/menu.rb', line 61 def parent.try(:name) unless self.orphan? end |
#parent_menu_name=(name) ⇒ Object
65 66 67 68 69 70 71 |
# File 'app/models/menu.rb', line 65 def (name) if name.present? && Menu.find_by_name(name) self.parent_id = Menu.find_by_name(name).id else self.parent_id = nil end end |
#self_and_siblings ⇒ Object
52 53 54 55 56 57 58 |
# File 'app/models/menu.rb', line 52 def self_and_siblings if has_parent? parent.children else Menu.orphans end end |
#siblings ⇒ Object
48 49 50 |
# File 'app/models/menu.rb', line 48 def siblings self_and_siblings - [self] end |
#to_param ⇒ Object
14 15 16 |
# File 'app/models/menu.rb', line 14 def to_param name ? "#{id}-#{name.to_url}" : id end |