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



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

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



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

def destroy
  authorize! :destroy, page

  DestroyStaticPage.call(page, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("static_pages.destroy.success", scope: "decidim.admin")
      redirect_to static_pages_path
    end
  end
end

#editObject



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

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

#indexObject



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

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

#newObject



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

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

#showObject



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

def show
  authorize! :read, page
end

#updateObject



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

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