Class: Post
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Post
- Defined in:
- app/models/post.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.by_date(year, month = nil, day = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/post.rb', line 12 def self.by_date(year, month=nil, day=nil) start_date = Date.new(year, month || 1, day || 1) end_date = nil if day end_date = start_date.advance(:days => 1) elsif month end_date = start_date.advance(:months => 1) else end_date = start_date.advance(:years => 1) end where('published_on BETWEEN ? AND ?', start_date, end_date) end |
.group_dates ⇒ Object
27 28 29 30 31 |
# File 'app/models/post.rb', line 27 def self.group_dates select('published_on, title, permalink'). group_by {|post| post.published_on.to_date.advance(:days => -(post.published_on.day-1)) }. group_by {|date| date.first.year } end |
Instance Method Details
#status ⇒ Object
33 34 35 |
# File 'app/models/post.rb', line 33 def status publish ? "published" : "unpublished" end |
#to_param ⇒ Object
37 38 39 40 |
# File 'app/models/post.rb', line 37 def to_param return permalink unless permalink.blank? title.to_url end |