Class: Effective::PostsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/effective/posts_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/effective/posts_controller.rb', line 7

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

#showObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/effective/posts_controller.rb', line 23

def show
  @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 if params[:edit].to_s != 'true'
  @posts = @posts.includes(:regions)

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

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

  @page_title = @post.title
end