Class: Atreides::Page
- Includes:
- Base::AasmStates, Base::Taggable, Base::Validation, Extendable
- Defined in:
- app/models/atreides/page.rb
Class Method Summary collapse
Instance Method Summary collapse
- #children ⇒ Object
- #parent ⇒ Object
- #parents ⇒ Object
- #root ⇒ Object
-
#thumbnail(size = :thumb) ⇒ Object
Instance Methods.
- #update_slug ⇒ Object
Methods included from Base::Validation
Methods included from Base::AasmStates
Methods included from Base::Taggable
Methods inherited from Base
Class Method Details
.base_class ⇒ Object
53 54 55 |
# File 'app/models/atreides/page.rb', line 53 def base_class self end |
Instance Method Details
#children ⇒ Object
74 75 76 |
# File 'app/models/atreides/page.rb', line 74 def children @children ||= self.class.find_all_by_parent_id(id) end |
#parent ⇒ Object
78 79 80 |
# File 'app/models/atreides/page.rb', line 78 def parent @parent ||= parent_of end |
#parents ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/atreides/page.rb', line 82 def parents @parents ||= [] return @parents unless @parents.empty? prnt = self while prnt.parent_id? prnt = parent_of(prnt) @parents << prnt end @parents end |
#root ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'app/models/atreides/page.rb', line 94 def root() return @root unless @root.nil? prnt = self.parent || self while prnt.parent_id? prnt = parent_of(prnt) end @root = prnt end |
#thumbnail(size = :thumb) ⇒ Object
Instance Methods
62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/atreides/page.rb', line 62 def thumbnail(size = :thumb) # Find the first thumbnail image url = nil url = photos.first.image.url(size) unless photos.empty? # FIXME: THIS NEEDS TO BE MOVED TO A VIEW/PRESENTER/DECORATOR # asset_path('atreides/missing_thumb.png') url || "/images/missing_thumb.png" end |
#update_slug ⇒ Object
44 45 46 47 |
# File 'app/models/atreides/page.rb', line 44 def update_slug # Set slug if not set or changed self.slug = title.to_s.parameterize if !slug? or (!new_record? && title_changed?) end |