Class: Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Page
- Defined in:
- app/models/page.rb
Class Method Summary collapse
- .tag_counts ⇒ Object
-
.tagged_with(name) ⇒ Object
tagging related methods.
- .tkh_search_indexable_fields ⇒ Object
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
- #published? ⇒ Boolean
- #siblings ⇒ Object
- #tag_list ⇒ Object
- #tag_list=(names) ⇒ Object
- #to_param ⇒ Object
Class Method Details
.tag_counts ⇒ Object
80 81 82 83 |
# File 'app/models/page.rb', line 80 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
76 77 78 |
# File 'app/models/page.rb', line 76 def self.tagged_with(name) Tag.find_by_name!(name).pages end |
.tkh_search_indexable_fields ⇒ Object
10 11 12 13 14 15 16 |
# File 'app/models/page.rb', line 10 def self.tkh_search_indexable_fields indexable_fields = { title: 8, description: 3, body: 2 } end |
Instance Method Details
#author_name ⇒ Object
107 108 109 |
# File 'app/models/page.rb', line 107 def .try(:formal_name) end |
#author_name=(formal_name) ⇒ Object
110 111 112 113 114 115 |
# File 'app/models/page.rb', line 110 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
58 59 60 |
# File 'app/models/page.rb', line 58 def children Page.published.with_parent_id(id) end |
#has_children? ⇒ Boolean
54 55 56 |
# File 'app/models/page.rb', line 54 def has_children? Page.with_parent_id(id).published.count >= 1 end |
#has_siblings? ⇒ Boolean
66 67 68 |
# File 'app/models/page.rb', line 66 def has_siblings? Page.with_parent_id(parent_id).published.count >= 1 end |
#nickname ⇒ Object
40 41 42 |
# File 'app/models/page.rb', line 40 def nickname @nickname ||= short_title || title end |
#orphan? ⇒ Boolean
menu related instance methods
50 51 52 |
# File 'app/models/page.rb', line 50 def orphan? parent_id == nil end |
#parent ⇒ Object
62 63 64 |
# File 'app/models/page.rb', line 62 def parent Page.find(parent_id) end |
#parent_page_title ⇒ Object
autocomplete related instance methods
96 97 98 |
# File 'app/models/page.rb', line 96 def parent_page_title parent.try(:title) unless self.orphan? end |
#parent_page_title=(title) ⇒ Object
99 100 101 102 103 104 105 |
# File 'app/models/page.rb', line 99 def parent_page_title=(title) if title.present? && Page.where(title: title) self.parent_id = Page.where(title: title).first.id else self.parent_id = nil end end |
#published? ⇒ Boolean
44 45 46 |
# File 'app/models/page.rb', line 44 def published? published_at.present? ? true : false end |
#siblings ⇒ Object
70 71 72 |
# File 'app/models/page.rb', line 70 def siblings Page.published.with_parent_id(parent_id) end |
#tag_list ⇒ Object
85 86 87 |
# File 'app/models/page.rb', line 85 def tag_list .map(&:name).join(" ") end |
#tag_list=(names) ⇒ Object
89 90 91 92 93 |
# File 'app/models/page.rb', line 89 def tag_list=(names) self. = names.split(" ").map do |n| Tag.where(name: n.strip).first_or_create! end end |
#to_param ⇒ Object
25 26 27 |
# File 'app/models/page.rb', line 25 def to_param title ? "#{id}-#{title.to_url}" : id end |