Sha256: 86f2c10a757776fd7c0e8a1a2af4acc591a6846d68e172475c44992ea241d7e3

Contents?: true

Size: 1.53 KB

Versions: 13

Compression:

Stored size: 1.53 KB

Contents

module Effective
  class PostsController < ApplicationController
    layout (EffectivePosts.layout.kind_of?(Hash) ? EffectivePosts.layout[:posts] : EffectivePosts.layout)

    after_action :monkey_patch_for_kaminari, :only => [:index]

    def index
      @posts = (Rails::VERSION::MAJOR > 3 ? Effective::Post.all : Effective::Post.scoped)

      @posts = @posts.for_role(current_user.try(:roles)) if defined?(EffectiveRoles)
      @posts = @posts.with_category(params[:category]) if params[:category]
      @posts = @posts.published
      @posts = @posts.includes(:regions)

      @posts = @posts.order("#{EffectivePosts.posts_table_name}.published_at DESC")
      @posts = @posts.page(params[:page]).per(EffectivePosts.per_page)

      EffectivePosts.authorized?(self, :index, Effective::Post)

      @page_title = (params[:category] || 'Posts').titleize
    end

    def show
      @posts = (Rails::VERSION::MAJOR > 3 ? Effective::Post.all : Effective::Post.scoped)

      @posts = @posts.with_category(params[:category]) if params[:category]
      @posts = @posts.published if params[:edit].to_s != 'true'
      @posts = @posts.includes(:regions)

      @post = @posts.find(params[:id])

      if defined?(EffectiveRoles)
        raise Effective::AccessDenied unless @post.roles_permit?(current_user)
      end

      EffectivePosts.authorized?(self, :show, @post)

      @page_title = @post.title
    end

    private

    def monkey_patch_for_kaminari
      @template = @template.tap { |template| template.extend(EffectiveKaminariHelper) }
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
effective_posts-0.4.6 app/controllers/effective/posts_controller.rb
effective_posts-0.4.5 app/controllers/effective/posts_controller.rb
effective_posts-0.4.4 app/controllers/effective/posts_controller.rb
effective_posts-0.4.3 app/controllers/effective/posts_controller.rb
effective_posts-0.4.2 app/controllers/effective/posts_controller.rb
effective_posts-0.4.1 app/controllers/effective/posts_controller.rb
effective_posts-0.4.0 app/controllers/effective/posts_controller.rb
effective_posts-0.3.0 app/controllers/effective/posts_controller.rb
effective_posts-0.2.6 app/controllers/effective/posts_controller.rb
effective_posts-0.2.5 app/controllers/effective/posts_controller.rb
effective_posts-0.2.4 app/controllers/effective/posts_controller.rb
effective_posts-0.2.3 app/controllers/effective/posts_controller.rb
effective_posts-0.2.2 app/controllers/effective/posts_controller.rb