Sha256: 144f9b023b584afce6773b597ff4145c40b78535937bc040938d065c47eae996

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

class Comfy::Blog::PostsController < Comfy::Blog::BaseController
  
  skip_before_action :load_blog, :only => [:serve]
  
  # due to fancy routing it's hard to say if we need show or index
  # action. let's figure it out here.
  def serve
    # if there are more than one blog, blog_path is expected
    if @cms_site.blogs.count >= 2 
      params[:blog_path] = params.delete(:slug) if params[:blog_path].blank?
    end
    
    load_blog
    
    if params[:slug].present?
      show && render(:show)
    else
      index && render(:index)
    end
  end

  def index
    scope = if params[:year]
      scope = @blog.posts.published.for_year(params[:year])
      params[:month] ? scope.for_month(params[:month]) : scope
    else
      @blog.posts.published
    end

    limit = ComfyBlog.config.posts_per_page
    respond_to do |format|
      format.html do
        @posts = scope.page(params[:page]).per(limit)
      end
      format.rss do
        @posts = scope.limit(limit)
      end
    end
  end
  
  def show
    @post = if params[:slug] && params[:year] && params[:month]
      @blog.posts.published.where(:year => params[:year], :month => params[:month], :slug => params[:slug]).first!
    else
      @blog.posts.published.where(:slug => params[:slug]).first!
    end
    @comment = @post.comments.new

  rescue ActiveRecord::RecordNotFound
    render :cms_page => '/404', :status => 404
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
comfy_blog-1.12.2 app/controllers/comfy/blog/posts_controller.rb
comfy_blog-1.12.1 app/controllers/comfy/blog/posts_controller.rb
comfy_blog-1.12.0 app/controllers/comfy/blog/posts_controller.rb