Class: Decidim::Budgets::Admin::CreateBudget

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

Overview

This command is executed when the user creates an Budget from the admin panel.

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ CreateBudget

Returns a new instance of CreateBudget.


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

def initialize(form)
  @form = form
end

Instance Method Details

#callObject

Creates the budget if valid.

Broadcasts :ok if successful, :invalid otherwise.


16
17
18
19
20
21
22
# File 'decidim-budgets/app/commands/decidim/budgets/admin/create_budget.rb', line 16

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

  create_budget!

  broadcast(:ok, budget)
end