Class: Decidim::Lausanne::Budgets::Admin::LausanneBudgetsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/decidim/lausanne/budgets/admin/lausanne_budgets_controller.rb

Overview

This controller allows the create or update a budget.

Instance Method Summary collapse

Methods inherited from ApplicationController

#project, #projects

Instance Method Details

#createObject



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

def create
  enforce_permission_to :create, :budget
  @form = form(LausanneBudgetForm).from_params(params, current_component: current_component)
  CreateBudget.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("lausanne_budgets.create.success", scope: "decidim.lausanne_budgets.admin")
      redirect_to lausanne_budgets_path
    end
    on(:invalid) do
      flash.now[:alert] = I18n.t("lausanne_budgets.create.invalid", scope: "decidim.lausanne_budgets.admin")
      render action: "new"
    end
  end
end

#destroyObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/decidim/lausanne/budgets/admin/lausanne_budgets_controller.rb', line 56

def destroy
  enforce_permission_to :delete, :budget, budget: budget

  DestroyBudget.call(budget, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("budgets.destroy.success", scope: "decidim.lausanne_budgets.admin")
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("budgets.destroy.invalid", scope: "decidim.lausanne_budgets.admin")
    end
  end

  redirect_to lausanne_budgets_path
end

#editObject



34
35
36
37
# File 'app/controllers/decidim/lausanne/budgets/admin/lausanne_budgets_controller.rb', line 34

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

#indexObject



12
# File 'app/controllers/decidim/lausanne/budgets/admin/lausanne_budgets_controller.rb', line 12

def index; end

#newObject



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

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

#updateObject



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

def update
  enforce_permission_to :update, :budget, budget: budget
  @form = form(LausanneBudgetForm).from_params(params, current_component: current_component)

  UpdateBudget.call(@form, budget) do
    on(:ok) do
      flash[:notice] = I18n.t("budgets.update.success", scope: "decidim.lausanne_budgets.admin")
      redirect_to lausanne_budgets_path
    end

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