Class: Decidim::Debates::CreateDebate

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

Overview

This command is executed when the user creates a Debate from the public views.

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ CreateDebate

Returns a new instance of CreateDebate.



8
9
10
# File 'app/commands/decidim/debates/create_debate.rb', line 8

def initialize(form)
  @form = form
end

Instance Method Details

#callObject

Creates the debate if valid.

Broadcasts :ok if successful, :invalid otherwise.



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

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

  with_events(with_transaction: true) do
    create_debate
  end
  send_notification_to_author_followers
  send_notification_to_space_followers
  follow_debate
  broadcast(:ok, debate)
end