Class: Decidim::Admin::StaticPagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/decidim/admin/static_pages_controller.rb

Overview

Controller that allows managing all pages at the admin panel.

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability_klass, #user_not_authorized_path

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 19

def create
  authorize! :new, StaticPage
  @form = form(StaticPageForm).from_params(form_params)

  CreateStaticPage.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("static_pages.create.success", scope: "decidim.admin")
      redirect_to static_pages_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("static_pages.create.error", scope: "decidim.admin")
      render :new
    end
  end
end

#destroyObject



63
64
65
66
67
68
69
70
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 63

def destroy
  authorize! :destroy, page
  page.destroy!

  flash[:notice] = I18n.t("static_pages.destroy.success", scope: "decidim.admin")

  redirect_to static_pages_path
end

#editObject



36
37
38
39
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 36

def edit
  authorize! :update, page
  @form = form(StaticPageForm).from_model(page)
end

#indexObject



9
10
11
12
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 9

def index
  authorize! :index, StaticPage
  @pages = collection
end

#newObject



14
15
16
17
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 14

def new
  authorize! :new, StaticPage
  @form = form(StaticPageForm).instance
end

#showObject



59
60
61
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 59

def show
  authorize! :read, page
end

#updateObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 41

def update
  @page = collection.find(params[:id])
  authorize! :update, page
  @form = form(StaticPageForm).from_params(form_params)

  UpdateStaticPage.call(page, @form) do
    on(:ok) do
      flash[:notice] = I18n.t("static_pages.update.success", scope: "decidim.admin")
      redirect_to static_pages_path
    end

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