Class: Panda::CMS::Admin::PagesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/panda/cms/admin/pages_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#set_current_request_details

Methods included from Panda::CMS::ApplicationHelper

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

Instance Method Details

#createObject

POST /admin/pages



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/panda/cms/admin/pages_controller.rb', line 39

def create
  page = Panda::CMS::Page.new(page_params)

  # Normalize empty path to nil so presence validation triggers
  page.path = nil if page.path.blank?

  # Set the full path before validation if we have a parent
  if page.parent && page.parent.path != "/" && page.path.present? && !page.path.start_with?(page.parent.path)
    # Only prepend parent path if it's not already included
    page.path = page.parent.path + page.path
  end

  if page.save
    redirect_to edit_admin_cms_page_path(page), notice: "The page was successfully created."
  else
    flash.now[:error] = page.errors.full_messages.to_sentence
    locals = setup_new_page_form(page: page)
    render :new, locals: locals, status: :unprocessable_entity
  end
end

#editObject

Loads the page editor



27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/panda/cms/admin/pages_controller.rb', line 27

def edit
  # Add all ancestor pages to breadcrumbs (excluding homepage at depth 0)
  page.ancestors.select { |anc| anc.depth > 0 }.each do |ancestor|
    add_breadcrumb ancestor.title, edit_admin_cms_page_path(ancestor)
  end

  add_breadcrumb page.title, edit_admin_cms_page_path(page)

  render :edit, locals: {page: page, template: page.template}
end

#indexObject

Lists all pages which can be managed by the administrator



13
14
15
16
# File 'app/controllers/panda/cms/admin/pages_controller.rb', line 13

def index
  homepage = Panda::CMS::Page.find_by(path: "/")
  render :index, locals: {root_page: homepage}
end

#newObject

Loads the add page form



20
21
22
23
# File 'app/controllers/panda/cms/admin/pages_controller.rb', line 20

def new
  locals = setup_new_page_form(page: page)
  render :new, locals: locals
end

#updateObject



62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/panda/cms/admin/pages_controller.rb', line 62

def update
  if page.update(page_params)
    redirect_to edit_admin_cms_page_path(page),
      status: :see_other,
      flash: {success: "This page was successfully updated!"}
  else
    flash[:error] = "There was an error updating the page."
    render :edit, locals: {page: page, template: page.template}, status: :unprocessable_entity
  end
end