Class: Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Page
- Defined in:
- app/models/page.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
Class Method Summary collapse
- .tag_counts ⇒ Object
-
.tagged_with(name) ⇒ Object
tagging related methods.
Instance Method Summary collapse
- #author_name ⇒ Object
- #author_name=(formal_name) ⇒ Object
- #children ⇒ Object
- #has_children? ⇒ Boolean
- #has_siblings? ⇒ Boolean
- #nickname ⇒ Object
-
#orphan? ⇒ Boolean
menu related instance methods.
- #parent ⇒ Object
-
#parent_page_title ⇒ Object
autocomplete related instance methods.
- #parent_page_title=(title) ⇒ Object
- #siblings ⇒ Object
- #tag_list ⇒ Object
- #tag_list=(names) ⇒ Object
- #to_param ⇒ Object
Class Method Details
.tag_counts ⇒ Object
72 73 74 75 |
# File 'app/models/page.rb', line 72 def self.tag_counts Tag.select("tags.*, count(taggings.tag_id) as count"). joins(:taggings).group("taggings.tag_id") end |
.tagged_with(name) ⇒ Object
tagging related methods
68 69 70 |
# File 'app/models/page.rb', line 68 def self.tagged_with(name) Tag.find_by_name!(name).pages end |
Instance Method Details
#author_name ⇒ Object
99 100 101 |
# File 'app/models/page.rb', line 99 def .try(:formal_name) end |
#author_name=(formal_name) ⇒ Object
102 103 104 105 106 107 |
# File 'app/models/page.rb', line 102 def (formal_name) name_as_array = formal_name.split(',') last_name = name_as_array[0].strip first_name = name_as_array[1].strip self. = User.where("last_name = ? AND first_name = ?", last_name, first_name).first.id end |
#children ⇒ Object
50 51 52 |
# File 'app/models/page.rb', line 50 def children Page.published.with_parent_id(id) end |
#has_children? ⇒ Boolean
46 47 48 |
# File 'app/models/page.rb', line 46 def has_children? Page.with_parent_id(id).published.count >= 1 end |
#has_siblings? ⇒ Boolean
58 59 60 |
# File 'app/models/page.rb', line 58 def has_siblings? Page.with_parent_id(parent_id).published.count >= 1 end |
#nickname ⇒ Object
36 37 38 |
# File 'app/models/page.rb', line 36 def nickname @nickname ||= short_title || title end |
#orphan? ⇒ Boolean
menu related instance methods
42 43 44 |
# File 'app/models/page.rb', line 42 def orphan? parent_id == nil end |
#parent ⇒ Object
54 55 56 |
# File 'app/models/page.rb', line 54 def parent Page.find(parent_id) end |
#parent_page_title ⇒ Object
autocomplete related instance methods
88 89 90 |
# File 'app/models/page.rb', line 88 def parent_page_title parent.try(:title) unless self.orphan? end |
#parent_page_title=(title) ⇒ Object
91 92 93 94 95 96 97 |
# File 'app/models/page.rb', line 91 def parent_page_title=(title) if title.present? && Page.find_by_title(title) self.parent_id = Page.find_by_title(title).id else self.parent_id = nil end end |
#siblings ⇒ Object
62 63 64 |
# File 'app/models/page.rb', line 62 def siblings Page.published.with_parent_id(parent_id) end |
#tag_list ⇒ Object
77 78 79 |
# File 'app/models/page.rb', line 77 def tag_list .map(&:name).join(" ") end |
#tag_list=(names) ⇒ Object
81 82 83 84 85 |
# File 'app/models/page.rb', line 81 def tag_list=(names) self. = names.split(" ").map do |n| Tag.where(name: n.strip).first_or_create! end end |
#to_param ⇒ Object
21 22 23 |
# File 'app/models/page.rb', line 21 def to_param title ? "#{id}-#{title.to_url}" : id end |