Class: Decidim::Budgets::Admin::BudgetsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Admin::HasTrashableResources
Defined in:
app/controllers/decidim/budgets/admin/budgets_controller.rb

Overview

This controller allows the create or update a budget.

Instance Method Summary collapse

Methods inherited from ApplicationController

#maps_enabled?, #project, #projects

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/decidim/budgets/admin/budgets_controller.rb', line 18

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", status: :unprocessable_content
    end
  end
end

#editObject



35
36
37
38
# File 'app/controllers/decidim/budgets/admin/budgets_controller.rb', line 35

def edit
  enforce_permission_to(:update, :budget, budget:)
  @form = form(BudgetForm).from_model(budget)
end

#newObject



13
14
15
16
# File 'app/controllers/decidim/budgets/admin/budgets_controller.rb', line 13

def new
  enforce_permission_to :create, :budget
  @form = form(BudgetForm).instance
end

#updateObject



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

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", status: :unprocessable_content
    end
  end
end