Class: Effective::PagesController

Inherits:
ApplicationController
  • Object
show all
Includes:
CrudController
Defined in:
app/controllers/effective/pages_controller.rb

Instance Method Summary collapse

Instance Method Details

#showObject

Raises:

  • (ActionController::RoutingError)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/effective/pages_controller.rb', line 5

def show
  @pages = Effective::Page.deep.all
  @pages = @pages.published unless EffectiveResources.authorized?(self, :admin, :effective_pages)

  @page = @pages.find(params[:id])

  raise ActionController::RoutingError.new('Not Found') if @page.menu_root_with_children?

  if @page.authenticate_user? || @page.roles.present?
    authenticate_user!
  end

  raise Effective::AccessDenied.new('Access Denied', :show, @page) unless @page.roles_permit?(current_user)
  EffectiveResources.authorize!(self, :show, @page)

  @page_title = @page.title
  @meta_description = @page.meta_description
  @canonical_url = effective_pages.page_url(@page)

  if EffectiveResources.authorized?(self, :admin, :effective_pages)
    flash.now[:warning] = [
      'Hi Admin!',
      ('You are viewing a draft page.' unless @page.published?),
      ("<a href='#{effective_pages.edit_admin_page_path(@page)}' class='alert-link' data-turbolinks='false'>Click here to edit this page</a>.")
    ].compact.join(' ')
  end

  template = File.join(EffectivePages.pages_path, @page.template)
  layout = File.join(EffectivePages.layouts_path, @page.layout)

  respond_to do |format|
    format.html { render(template, layout: layout, locals: { page: @page }) }
  end
end