Class: Decidim::Admin::ScopesController

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

Overview

Controller that allows managing all scopes 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/scopes_controller.rb', line 19

def create
  authorize! :new, Scope
  @form = form(ScopeForm).from_params(params)

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

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

#destroyObject



59
60
61
62
63
64
65
66
# File 'app/controllers/decidim/admin/scopes_controller.rb', line 59

def destroy
  authorize! :destroy, scope
  scope.destroy!

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

  redirect_to scopes_path
end

#editObject



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

def edit
  authorize! :update, scope
  @form = form(ScopeForm).from_model(scope)
end

#indexObject



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

def index
  authorize! :index, Scope
  @scopes = collection
end

#newObject



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

def new
  authorize! :new, Scope
  @form = form(ScopeForm).instance
end

#updateObject



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

def update
  @scope = collection.find(params[:id])
  authorize! :update, scope
  @form = form(ScopeForm).from_params(params)

  UpdateScope.call(scope, @form) do
    on(:ok) do
      flash[:notice] = I18n.t("scopes.update.success", scope: "decidim.admin")
      redirect_to scopes_path
    end

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