aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/refinery/blog/posts_controller.rb2
-rw-r--r--app/models/refinery/blog/post.rb8
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)