Class: Decidim::Pages::Admin::PagesController

Inherits:
ApplicationController show all
Includes:
Admin::HasTrashableResources
Defined in:
decidim-pages/app/controllers/decidim/pages/admin/pages_controller.rb

Overview

This controller allows the user to update a Page.

Instance Method Summary collapse

Methods inherited from Admin::Components::BaseController

#current_component, #current_participatory_space, #parent_path, #permission_class_chain, #permission_scope, #permissions_context, #set_component_breadcrumb_item, #skip_manage_component_permission

Methods included from RegistersPermissions

register_permissions

Methods inherited from Admin::ApplicationController

#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from TranslatableAttributes

#attachment?, #default_locale?

Methods included from NeedsSnippets

#snippets

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#editObject



10
11
12
13
14
# File 'decidim-pages/app/controllers/decidim/pages/admin/pages_controller.rb', line 10

def edit
  enforce_permission_to :update, :page

  @form = form(Admin::PageForm).from_model(page)
end

#updateObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'decidim-pages/app/controllers/decidim/pages/admin/pages_controller.rb', line 16

def update
  enforce_permission_to :update, :page

  @form = form(Admin::PageForm).from_params(params)

  Admin::UpdatePage.call(@form, page) do
    on(:ok) do
      flash[:notice] = I18n.t("pages.update.success", scope: "decidim.pages.admin")
      redirect_to parent_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("pages.update.invalid", scope: "decidim.pages.admin")
      render action: "edit", status: :unprocessable_entity
    end
  end
end