aboutsummaryrefslogtreecommitdiffstats
path: root/app/helpers
diff options
context:
space:
mode:
authorJamie Winsor <jamie@enmasse.com>2011-09-19 15:35:47 -0700
committerJamie Winsor <jamie@enmasse.com>2011-09-19 15:35:47 -0700
commitd37ef11f63904b0daa0dcf240dd5a55025423af3 (patch)
tree21838dd05009849dd02110a4b5dafb51af38a36a /app/helpers
parent7fe5fe5de6a0e7ef8ac011d7d6b85c61a2f6be96 (diff)
downloadrefinerycms-blog-d37ef11f63904b0daa0dcf240dd5a55025423af3.tar.gz
refinerycms-blog-d37ef11f63904b0daa0dcf240dd5a55025423af3.tar.bz2
refinerycms-blog-d37ef11f63904b0daa0dcf240dd5a55025423af3.zip
Abstract filter methods into controller helpers
This will enable users to include the controller helper into their own controllers to perform common functions - such as finding a blog post or listing all blog posts.
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/refinery/blog_controller_helper.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/helpers/refinery/blog_controller_helper.rb b/app/helpers/refinery/blog_controller_helper.rb
new file mode 100644
index 0000000..2edc2f6
--- /dev/null
+++ b/app/helpers/refinery/blog_controller_helper.rb
@@ -0,0 +1,28 @@
+module Refinery
+ module BlogControllerHelper
+
+ protected
+
+ def find_blog_post
+ unless (@blog_post = Refinery::BlogPost.find(params[:id])).try(:live?)
+ if refinery_user? and current_user.authorized_plugins.include?("refinerycms_blog")
+ @blog_post = Refinery::BlogPost.find(params[:id])
+ else
+ error_404
+ end
+ end
+ end
+
+ def find_all_blog_posts
+ @blog_posts = Refinery::BlogPost.live.includes(:comments, :categories).page(params[:page])
+ end
+
+ def find_tags
+ @tags = Refinery::BlogPost.tag_counts_on(:tags)
+ end
+
+ def find_all_blog_categories
+ @blog_categories = Refinery::BlogCategory.all
+ end
+ end
+end