add popularity counter to blog posts as well as accessor for recent posts

This commit is contained in:
Jeff Shumate 2012-02-22 20:37:08 -07:00
parent 45cad84f49
commit 4f0b5f8223
4 changed files with 53 additions and 1 deletions

View file

@ -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) }

View file

@ -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)