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