Class: Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Page
- Defined in:
- app/models/page.rb
Overview
requires
* path ( unique, > 1 char and starts with a / ) * menu ( unique and > 3 chars ) * title ( > 3 chars ) * body ( > 3 chars )
named_scope(s)
* not_home (returns those pages where path is not just ‘/’) * roots
uses acts_as_list for parent / child relationship. As this is only a parent and child and no deeper, its ok. If it were to get any deeper, the list should probably be changed to something like a nested set.
Class Method Summary collapse
-
.by_path(path) ⇒ Object
named_scopes ALWAYS return an “Array” so if ONLY want one, MUST use a method.
Instance Method Summary collapse
Class Method Details
.by_path(path) ⇒ Object
named_scopes ALWAYS return an “Array” so if ONLY want one, MUST use a method. by_path returns the one(max) page that matches the given path.
64 65 66 67 68 69 70 |
# File 'app/models/page.rb', line 64 def self.by_path(path) page = find(:first, :conditions => { :path => path.downcase } ) end |
Instance Method Details
#adjust_path ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/page.rb', line 48 def adjust_path unless self.path.nil? # remove any duplicate /'s # self.path = path.gsub(/\/+/,'/') self.path.gsub!(/\/+/,'/') # add leading / if none # self.path = path.downcase self.path.downcase! end end |
#is_home? ⇒ Boolean
80 81 82 |
# File 'app/models/page.rb', line 80 def is_home? self.path == "/" end |
#root ⇒ Object
72 73 74 75 76 77 78 |
# File 'app/models/page.rb', line 72 def root page = self until page.parent == nil page = page.parent end page end |