Class: Post

Inherits:
Content
  • Object
show all
Defined in:
app/models/post.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.by_archive(*args) ⇒ Object



13
14
15
# File 'app/models/post.rb', line 13

def by_archive(*args)
  where("DATE(contents.published_at) = ?", Date.new(*args.map(&:to_i)).to_formatted_s(:db))
end


9
10
11
# File 'app/models/post.rb', line 9

def by_permalink(year, month, day, slug)
  by_archive(year, month, day).where(:slug => slug)
end

Instance Method Details

#nextObject



22
23
24
# File 'app/models/post.rb', line 22

def next
  section.posts.order(:published_at).where(Post.arel_table[:published_at].gt(published_at)).last
end


26
27
28
# File 'app/models/post.rb', line 26

def permalink
  "#{published_at.year}/#{published_at.month}/#{published_at.day}/#{slug}"
end

#previousObject



18
19
20
# File 'app/models/post.rb', line 18

def previous
  section.posts.order(:published_at).where(Post.arel_table[:published_at].lt(published_at)).first
end

#to_param(name = nil) ⇒ Object



30
31
32
# File 'app/models/post.rb', line 30

def to_param(name=nil)
  name == :permalink ? permalink : super()
end