Sha256: de0db133a89aff8b67bc376ef83a3644ecef1299a3467545b995373e231b46a8
Contents?: true
Size: 1.53 KB
Versions: 2
Compression:
Stored size: 1.53 KB
Contents
class Blog::PostsController < Spree::BaseController helper :products before_filter :get_sidebar, :only => [:index, :search, :show] def index @posts_by_month = Post.live.limit(50).group_by { |post| post.posted_at.strftime("%B %Y") } scope = Post.live if params[:year].present? year = params[:year].to_i month = 1 day = 1 if has_month = params[:month].present? if has_day = params[:day].present? day = params[:day].to_i end month = params[:month].to_i end start = Date.new(year, month, day) stop = start + 1.year if has_month stop = start + 1.month if has_day stop = start + 1.day end end scope = scope.where("posted_at >= ? AND posted_at <= ?", start, stop) end @posts = scope.page(params[:page]).per(Post.per_page) end def search query = params[:query].gsub(/%46/, '.') @posts = Post.live.tagged_with(query).page(params[:page]).per(Post.per_page) get_tags render :template => 'blog/posts/index' end def show @blog_config = BlogConfiguration.current @post = Post.live.includes(:tags, :images, :products).find_by_path(params[:id]) rescue nil return redirect_to archive_posts_path unless @post end def archive @posts = Post.live.all end def get_sidebar @archive_posts = Post.live.limit(10) @post_categories = PostCategory.all get_tags end def get_tags @tags = Post.live.tag_counts.order('count DESC').limit(25) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
spree_essential_blog-0.1.0 | app/controllers/blog/posts_controller.rb |
spree_essential_blog-0.1.0.rc1 | app/controllers/blog/posts_controller.rb |