Class: Decidim::Budgets::Admin::UpdateBudget

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/budgets/admin/update_budget.rb

Overview

This command is executed when the user updates a Budget from the admin panel.

Instance Method Summary collapse

Constructor Details

#initialize(form, budget) ⇒ UpdateBudget

Returns a new instance of UpdateBudget.



9
10
11
12
# File 'app/commands/decidim/budgets/admin/update_budget.rb', line 9

def initialize(form, budget)
  @form = form
  @budget = budget
end

Instance Method Details

#callObject

Updates the budget if valid.

Broadcasts :ok if successful, :invalid otherwise.



17
18
19
20
21
22
23
# File 'app/commands/decidim/budgets/admin/update_budget.rb', line 17

def call
  return broadcast(:invalid) if form.invalid?

  update_budget!

  broadcast(:ok, budget)
end