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



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

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



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

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



39
40
41
42
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 39

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

#indexObject



12
13
14
15
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 12

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

#newObject



17
18
19
20
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 17

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

#showObject



62
63
64
# File 'app/controllers/decidim/admin/static_pages_controller.rb', line 62

def show
  authorize! :read, page
end

#updateObject



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

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