add popularity counter to blog posts as well as accessor for recent posts
This commit is contained in:
parent
45cad84f49
commit
4f0b5f8223
4 changed files with 53 additions and 1 deletions
|
@ -23,6 +23,8 @@ module Refinery
|
|||
@comment = Comment.new
|
||||
|
||||
@canonical = url_for(:locale => ::Refinery::I18n.default_frontend_locale) if canonical?
|
||||
|
||||
@post.increment!(:access_count,1)
|
||||
|
||||
respond_with (@post) do |format|
|
||||
format.html { present(@post) }
|
||||
|
|
|
@ -78,6 +78,14 @@ module Refinery
|
|||
def live
|
||||
where( "published_at <= ? and draft = ?", Time.now, false)
|
||||
end
|
||||
|
||||
def recent(count)
|
||||
where("published_at <= ? and draft = ?", Time.now, false).limit(count)
|
||||
end
|
||||
|
||||
def popular(count)
|
||||
unscoped.order("access_count DESC").limit(count)
|
||||
end
|
||||
|
||||
def previous(item)
|
||||
where(["published_at < ? and draft = ?", item.published_at, false]).limit(1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue