diff options
author | Philip Arndt <parndt@gmail.com> | 2012-02-22 20:11:14 -0800 |
---|---|---|
committer | Philip Arndt <parndt@gmail.com> | 2012-02-22 20:11:14 -0800 |
commit | 5440fad815b060f10892516ec97286d8dc4c3f80 (patch) | |
tree | 0385daa4cc7a5d3ef76b172655bd51b898299999 /app | |
parent | 39fc08698209251dc7b5a2441487bac2a16ab650 (diff) | |
parent | 602759af1b89438435c59bffb10e2cbe4c60f834 (diff) | |
download | refinerycms-blog-5440fad815b060f10892516ec97286d8dc4c3f80.tar.gz refinerycms-blog-5440fad815b060f10892516ec97286d8dc4c3f80.tar.bz2 refinerycms-blog-5440fad815b060f10892516ec97286d8dc4c3f80.zip |
Merge pull request #200 from dmoose/rails-3-1-recent-popular
Rails 3 1 recent popular
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..bde3a9c 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..522e000 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) + live.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) |