Method: Effective::PostsController#show

Defined in:
app/controllers/effective/posts_controller.rb

#showObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/effective/posts_controller.rb', line 34

def show
  @posts ||= Effective::Post.posts(user: current_user, category: params[:category], unpublished: EffectiveResources.authorized?(self, :admin, :effective_posts))
  @post = @posts.find(params[:id])

  if @post.respond_to?(:roles_permit?)
    raise Effective::AccessDenied.new('Access Denied', :show, @post) unless @post.roles_permit?(current_user)
  end

  EffectiveResources.authorize!(self, :show, @post)

  if EffectiveResources.authorized?(self, :admin, :effective_posts)
    flash.now[:warning] = [
      'Hi Admin!',
      ('You are viewing a hidden post.' unless @post.published?),
      'Click here to',
      ("<a href='#{effective_posts.edit_admin_post_path(@post)}' class='alert-link'>edit post settings</a>.")
    ].compact.join(' ')
  end

  @page_title ||= @post.title
  @meta_description ||= @post.description
  @canonical_url ||= effective_posts.post_url(@post)
end