Class: Monologue::Post
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Monologue::Post
- Defined in:
- app/models/monologue/post.rb
Class Method Summary collapse
Instance Method Summary collapse
- #full_url ⇒ Object
- #published_in_future? ⇒ Boolean
- #tag!(tags_attr) ⇒ Object
- #tag_list ⇒ Object
- #tag_list=(tags_attr) ⇒ Object
Class Method Details
.page(p) ⇒ Object
41 42 43 44 45 46 47 |
# File 'app/models/monologue/post.rb', line 41 def self.page p per_page = Monologue.posts_per_page || 10 set_total_pages(per_page) p = (p.nil? ? 0 : p.to_i - 1) offset = p * per_page self.limit(per_page).offset(offset) end |
.set_total_pages(per_page) ⇒ Object
53 54 55 |
# File 'app/models/monologue/post.rb', line 53 def self.set_total_pages per_page @number_of_pages = self.count / per_page + (self.count % per_page == 0 ? 0 : 1) end |
.total_pages ⇒ Object
49 50 51 |
# File 'app/models/monologue/post.rb', line 49 def self.total_pages @number_of_pages end |
Instance Method Details
#full_url ⇒ Object
33 34 35 |
# File 'app/models/monologue/post.rb', line 33 def full_url "#{Monologue::Engine.routes.url_helpers.root_path}#{self.url}" end |
#published_in_future? ⇒ Boolean
37 38 39 |
# File 'app/models/monologue/post.rb', line 37 def published_in_future? self.published && self.published_at > DateTime.now end |
#tag!(tags_attr) ⇒ Object
27 28 29 30 31 |
# File 'app/models/monologue/post.rb', line 27 def tag!() self. = .map(&:strip).reject(&:blank?).map do |tag| Monologue::Tag.find_or_create_by_name(tag) end end |
#tag_list ⇒ Object
23 24 25 |
# File 'app/models/monologue/post.rb', line 23 def tag_list self..map { |tag| tag.name }.join(", ") if self. end |
#tag_list=(tags_attr) ⇒ Object
19 20 21 |
# File 'app/models/monologue/post.rb', line 19 def tag_list= self.tag!(.split(",")) end |