Class: Decidim::Admin::CategoriesController
Overview
Controller that allows managing categories.
Instance Method Summary
collapse
#current_ability_klass, #user_not_authorized_path
enhance_controller, extended, included
Instance Method Details
#create ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'decidim-admin/app/controllers/decidim/admin/categories_controller.rb', line 19
def create
authorize! :create, Decidim::Category
@form = form(CategoryForm).from_params(params, current_participatory_space: current_participatory_space)
CreateCategory.call(@form, current_participatory_space) do
on(:ok) do
flash[:notice] = I18n.t("categories.create.success", scope: "decidim.admin")
redirect_to categories_path(current_participatory_space)
end
on(:invalid) do
flash.now[:alert] = I18n.t("categories.create.error", scope: "decidim.admin")
render :new
end
end
end
|
#destroy ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'decidim-admin/app/controllers/decidim/admin/categories_controller.rb', line 65
def destroy
@category = collection.find(params[:id])
authorize! :destroy, @category
DestroyCategory.call(@category) do
on(:ok) do
flash[:notice] = I18n.t("categories.destroy.success", scope: "decidim.admin")
end
on(:invalid) do
flash[:alert] = I18n.t("categories.destroy.error", scope: "decidim.admin")
end
redirect_back(fallback_location: categories_path(current_participatory_space))
end
end
|
#edit ⇒ Object
36
37
38
39
40
|
# File 'decidim-admin/app/controllers/decidim/admin/categories_controller.rb', line 36
def edit
@category = collection.find(params[:id])
authorize! :update, @category
@form = form(CategoryForm).from_model(@category, current_participatory_space: current_participatory_space)
end
|
#index ⇒ Object
10
11
12
|
# File 'decidim-admin/app/controllers/decidim/admin/categories_controller.rb', line 10
def index
authorize! :read, Decidim::Category
end
|
#new ⇒ Object
14
15
16
17
|
# File 'decidim-admin/app/controllers/decidim/admin/categories_controller.rb', line 14
def new
authorize! :create, Decidim::Category
@form = form(CategoryForm).from_params({}, current_participatory_space: current_participatory_space)
end
|
#show ⇒ Object
60
61
62
63
|
# File 'decidim-admin/app/controllers/decidim/admin/categories_controller.rb', line 60
def show
@category = collection.find(params[:id])
authorize! :read, @category
end
|
#update ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'decidim-admin/app/controllers/decidim/admin/categories_controller.rb', line 42
def update
@category = collection.find(params[:id])
authorize! :update, @category
@form = form(CategoryForm).from_params(params, current_participatory_space: current_participatory_space)
UpdateCategory.call(@category, @form) do
on(:ok) do
flash[:notice] = I18n.t("categories.update.success", scope: "decidim.admin")
redirect_to categories_path(current_participatory_space)
end
on(:invalid) do
flash.now[:alert] = I18n.t("categories.update.error", scope: "decidim.admin")
render :edit
end
end
end
|