Class: Decidim::Debates::CreateDebate

Inherits:
Command
  • Object
show all
Defined in:
decidim-debates/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 'decidim-debates/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
26
# File 'decidim-debates/app/commands/decidim/debates/create_debate.rb', line 15

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

  transaction do
    create_debate
    send_notification_to_author_followers
    send_notification_to_space_followers
  end

  follow_debate
  broadcast(:ok, debate)
end