Class: Panda::CMS::Admin::PagesController
- Inherits:
-
BaseController
- Object
- Panda::Core::AdminController
- BaseController
- Panda::CMS::Admin::PagesController
- Defined in:
- app/controllers/panda/cms/admin/pages_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /admin/pages.
-
#edit ⇒ Object
Loads the page editor.
-
#index ⇒ Object
Lists all pages which can be managed by the administrator.
-
#new ⇒ Object
Loads the add page form.
- #update ⇒ Object
Methods included from Panda::CMS::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
#create ⇒ Object
POST /admin/pages
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/panda/cms/admin/pages_controller.rb', line 34 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..to_sentence locals = setup_new_page_form(page: page) render :new, locals: locals, status: :unprocessable_entity end end |
#edit ⇒ Object
Loads the page editor
27 28 29 30 31 |
# File 'app/controllers/panda/cms/admin/pages_controller.rb', line 27 def edit page.title, edit_admin_cms_page_path(page) render :edit, locals: {page: page, template: page.template} end |
#index ⇒ Object
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 |
#new ⇒ Object
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 |
#update ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/panda/cms/admin/pages_controller.rb', line 57 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, status: :unprocessable_entity end end |