Sha256: 876c17433605b6f7ec1d66b2587b09150a4d9986a71c6fc7c427f681429d5781

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

class Comfy::Blog::PostsController < Comfy::Cms::BaseController

  include Comfy::Paginate

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

    scope = scope.for_category(params[:category]) if params[:category]

    @blog_posts = comfy_paginate(scope, per_page: ComfyBlog.config.posts_per_page)
    render layout: ComfyBlog.config.app_layout
  end

  def show
    load_post

    render  inline: @cms_post.content_cache,
            layout: app_layout,
            content_type: "text/html"

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

private

  def load_post
    post_scope = @cms_site.blog_posts.published.where(slug: params[:slug])
    @cms_post = if params[:year] && params[:month]
      post_scope = post_scope.where(year: params[:year], month: params[:month]).first!
    else
      post_scope.first!
    end
    @cms_layout = @cms_post.layout
  end

  def app_layout
    return false unless @cms_layout
    @cms_layout.app_layout.present? ? @cms_layout.app_layout : false
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
comfy_blog-2.0.2 app/controllers/comfy/blog/posts_controller.rb
comfy_blog-2.0.1 app/controllers/comfy/blog/posts_controller.rb
comfy_blog-2.0.0 app/controllers/comfy/blog/posts_controller.rb