diff options
author | Jeff Shumate <jeff@catapulsion.net> | 2012-02-22 20:37:08 -0700 |
---|---|---|
committer | Jeff Shumate <jeff@catapulsion.net> | 2012-02-22 20:37:08 -0700 |
commit | 4f0b5f8223426644924807fc38f86ec245f4827b (patch) | |
tree | 28f4f4f2e59ea65e6c68adf416fa8220e1404a01 /app | |
parent | 45cad84f4986ec9a1d78a5ced1a842f7a9048b5d (diff) | |
download | refinerycms-blog-4f0b5f8223426644924807fc38f86ec245f4827b.tar.gz refinerycms-blog-4f0b5f8223426644924807fc38f86ec245f4827b.tar.bz2 refinerycms-blog-4f0b5f8223426644924807fc38f86ec245f4827b.zip |
add popularity counter to blog posts as well as accessor for recent posts
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/refinery/blog/posts_controller.rb | 2 | ||||
-rw-r--r-- | app/models/refinery/blog/post.rb | 8 |
2 files changed, 10 insertions, 0 deletions
diff --git a/app/controllers/refinery/blog/posts_controller.rb b/app/controllers/refinery/blog/posts_controller.rb index abd60f4..3309024 100644 --- a/app/controllers/refinery/blog/posts_controller.rb +++ b/app/controllers/refinery/blog/posts_controller.rb @@ -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) } diff --git a/app/models/refinery/blog/post.rb b/app/models/refinery/blog/post.rb index 822ddf7..d114dff 100644 --- a/app/models/refinery/blog/post.rb +++ b/app/models/refinery/blog/post.rb @@ -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) |