Class: PandaCms::PagesController

Inherits:
ApplicationController show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
app/controllers/panda_cms/pages_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_breadcrumb, #authenticate_admin_user!, #authenticate_user!, #breadcrumbs, #current_user, #set_current_request_details, #user_signed_in?

Methods included from ApplicationHelper

#active_link?, #block_link_to, #component, #level_indent, #menu_indent, #nav_class, #nav_highlight_colour_classes, #panda_cms_editor, #panda_cms_form_with, #selected_nav_highlight_colour_classes, #table_indent, #title_tag

Instance Method Details

#rootObject



5
6
7
8
# File 'app/controllers/panda_cms/pages_controller.rb', line 5

def root
  params[:path] = ""
  show
end

#showObject



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
39
40
41
42
43
44
45
# File 'app/controllers/panda_cms/pages_controller.rb', line 10

def show
  if PandaCms.config. && !user_signed_in?
    redirect_to panda_cms_maintenance_path and return
  end

  path_to_find = "/" + params[:path].to_s
  page = Page.find_by(path: path_to_find) || Page.find_by(path: "/404")
  PandaCms::Current.page = page
  layout = page&.template&.file_path

  # TODO: If page is active?
  if page && layout
    globals = {
      page: page,
      title: page.title
    }

    unless ignore_visit?
      RecordVisitJob.perform_later(
        url: request.url,
        user_agent: request.user_agent,
        referrer: request.referrer,
        ip_address: request.remote_ip,
        page_id: page.id,
        current_user_id: current_user&.id,
        params: params.to_unsafe_h.except(:controller, :action, :path),
        visited_at: Time.zone.now
      )
    end

    render inline: "", assigns: globals, status: :ok, layout: layout
  else
    # This works for now, but we may want to override in future (e.g. custom 404s)
    render file: "#{Rails.root}/public/404.html", layout: false, status: :not_found
  end
end