Sha256: e3772e4a229125b786a41dcdd2a8e53b611504a51a7dc0e53f19459b9ed8a796

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 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.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.5 app/controllers/comfy/blog/posts_controller.rb
comfy_blog-2.0.4 app/controllers/comfy/blog/posts_controller.rb
comfy_blog-2.0.3 app/controllers/comfy/blog/posts_controller.rb