Class: Decidim::Budgets::Admin::BudgetsController
Overview
This controller allows the create or update a budget.
Instance Method Summary
collapse
#maps_enabled?, #project, #projects
Instance Method Details
#create ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/controllers/decidim/budgets/admin/budgets_controller.rb', line 16
def create
enforce_permission_to :create, :budget
@form = form(BudgetForm).from_params(params, current_component:)
CreateBudget.call(@form) do
on(:ok) do
flash[:notice] = I18n.t("budgets.create.success", scope: "decidim.budgets.admin")
redirect_to budgets_path
end
on(:invalid) do
flash.now[:alert] = I18n.t("budgets.create.invalid", scope: "decidim.budgets.admin")
render action: "new"
end
end
end
|
#destroy ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'app/controllers/decidim/budgets/admin/budgets_controller.rb', line 55
def destroy
enforce_permission_to(:delete, :budget, budget:)
DestroyBudget.call(budget, current_user) do
on(:ok) do
flash[:notice] = I18n.t("budgets.destroy.success", scope: "decidim.budgets.admin")
end
on(:invalid) do
flash.now[:alert] = I18n.t("budgets.destroy.invalid", scope: "decidim.budgets.admin")
end
end
redirect_to budgets_path
end
|
#edit ⇒ Object
33
34
35
36
|
# File 'app/controllers/decidim/budgets/admin/budgets_controller.rb', line 33
def edit
enforce_permission_to(:update, :budget, budget:)
@form = form(BudgetForm).from_model(budget)
end
|
#new ⇒ Object
11
12
13
14
|
# File 'app/controllers/decidim/budgets/admin/budgets_controller.rb', line 11
def new
enforce_permission_to :create, :budget
@form = form(BudgetForm).instance
end
|
#update ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'app/controllers/decidim/budgets/admin/budgets_controller.rb', line 38
def update
enforce_permission_to(:update, :budget, budget:)
@form = form(BudgetForm).from_params(params, current_component:)
UpdateBudget.call(@form, budget) do
on(:ok) do
flash[:notice] = I18n.t("budgets.update.success", scope: "decidim.budgets.admin")
redirect_to budgets_path
end
on(:invalid) do
flash.now[:alert] = I18n.t("budgets.update.invalid", scope: "decidim.budgets.admin")
render action: "edit"
end
end
end
|