Sha256: dd8fc7574ab33faeedb09e47816953c15db3b7e3d604d09d37ee7a60311bdde9

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

class Blog::PostsController < ApplicationController
  
  layout ComfyBlog.config.public_layout
  
  def index
    scope = if params[:tag]
      Blog::Post.published.tagged_with(params[:tag])
    elsif params[:category]
      Blog::Post.published.categorized_as(params[:category])
    elsif params[:year]
      scope = Blog::Post.published.for_year(params[:year])
      params[:month] ? scope.for_month(params[:month]) : scope
    else
      Blog::Post.published
    end
    
    respond_to do |f|
      f.html do
        @posts = if defined? WillPaginate
          scope.paginate :per_page => ComfyBlog.config.posts_per_page, :page => params[:page]
        elsif defined? Kaminari
          scope.page(params[:page]).per(ComfyBlog.config.posts_per_page)
        else
          scope
        end
      end
      f.rss do
        @posts = scope.limit(ComfyBlog.config.posts_per_page)
      end
    end
  end
  
  def show
    @post = if params[:slug] && params[:year] && params[:month]
      Blog::Post.published.find_by_year_and_month_and_slug!(params[:year], params[:month], params[:slug])
    else
      Blog::Post.published.find(params[:id])
    end
  rescue ActiveRecord::RecordNotFound
    if defined? ComfortableMexicanSofa
      render :cms_page => '/404', :status => 404
    else
      render :text => 'Post not found', :status => 404
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
comfy_blog-0.1.8 app/controllers/blog/posts_controller.rb
comfy_blog-0.1.7 app/controllers/blog/posts_controller.rb
comfy_blog-0.1.6 app/controllers/blog/posts_controller.rb