aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUģis Ozols <ugis.ozolss@gmail.com>2011-07-27 22:41:42 +0300
committerUģis Ozols <ugis.ozolss@gmail.com>2011-07-27 22:41:42 +0300
commit109184377f96db0530228cb3a8c38fe042e710c0 (patch)
tree381fbe74bbc70ea899665411e40677599611bdec
parent164dc27a42876efdbd14db9e2d14311b4c119e52 (diff)
downloadrefinerycms-blog-109184377f96db0530228cb3a8c38fe042e710c0.tar.gz
refinerycms-blog-109184377f96db0530228cb3a8c38fe042e710c0.tar.bz2
refinerycms-blog-109184377f96db0530228cb3a8c38fe042e710c0.zip
Move per_page pagination stuff into model to dry up posts controller.
-rw-r--r--app/controllers/refinery/blog/posts_controller.rb16
-rw-r--r--app/models/refinery/blog_post.rb3
2 files changed, 9 insertions, 10 deletions
diff --git a/app/controllers/refinery/blog/posts_controller.rb b/app/controllers/refinery/blog/posts_controller.rb
index f055797..408359f 100644
--- a/app/controllers/refinery/blog/posts_controller.rb
+++ b/app/controllers/refinery/blog/posts_controller.rb
@@ -54,18 +54,16 @@ module Refinery
date = "#{params[:month]}/#{params[:year]}"
@archive_date = Time.parse(date)
@date_title = @archive_date.strftime('%B %Y')
- @blog_posts = BlogPost.live.by_archive(@archive_date).paginate({
- :page => params[:page],
- :per_page => Refinery::Setting.find_or_set(:blog_posts_per_page, 10)
- })
+ @blog_posts = Refinery::BlogPost.live
+ .by_archive(@archive_date)
+ .page(params[:page])
else
date = "01/#{params[:year]}"
@archive_date = Time.parse(date)
@date_title = @archive_date.strftime('%Y')
- @blog_posts = Refinery::live.by_year(@archive_date).paginate({
- :page => params[:page],
- :per_page => Refinery::Setting.find_or_set(:blog_posts_per_page, 10)
- })
+ @blog_posts = Refinery::BlogPost.live
+ .by_year(@archive_date)
+ .page(params[:page])
end
respond_with (@blog_posts)
end
@@ -75,7 +73,6 @@ module Refinery
@tag_name = @tag.name
@blog_posts = Refinery::BlogPost.tagged_with(@tag_name)
.page(params[:page])
- .per(Refinery::Setting.find_or_set(:blog_posts_per_page, 10))
end
protected
@@ -94,7 +91,6 @@ module Refinery
@blog_posts = Refinery::BlogPost.live
.includes(:comments, :categories)
.page(params[:page])
- .per(Refinery::Setting.find_or_set(:blog_posts_per_page, 10))
end
def find_tags
diff --git a/app/models/refinery/blog_post.rb b/app/models/refinery/blog_post.rb
index 12ce6f2..5eb2a6f 100644
--- a/app/models/refinery/blog_post.rb
+++ b/app/models/refinery/blog_post.rb
@@ -111,6 +111,9 @@ module Refinery
end
end
end
+
+ # how many items to show per page
+ paginates_per Refinery::Setting.find_or_set(:blog_posts_per_page, 10)
end
end