Class: Decidim::Debates::Admin::CreateDebate

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

Overview

This command is executed when the user creates a Debate from the admin panel.

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ CreateDebate

Returns a new instance of CreateDebate.


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

def initialize(form)
  @form = form
end

Instance Method Details

#callObject

Creates the debate if valid.

Broadcasts :ok if successful, :invalid otherwise.


16
17
18
19
20
21
22
23
24
# File 'decidim-debates/app/commands/decidim/debates/admin/create_debate.rb', line 16

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

  transaction do
    create_debate
    send_notification_to_space_followers
  end
  broadcast(:ok)
end