Class: Decidim::Meetings::CreateAnswer

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/meetings/create_answer.rb

Overview

This command is executed when the user creates an Answer in a meeting poll.

Instance Method Summary collapse

Constructor Details

#initialize(form, questionnaire) ⇒ CreateAnswer

Returns a new instance of CreateAnswer.



9
10
11
12
# File 'app/commands/decidim/meetings/create_answer.rb', line 9

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

Instance Method Details

#callObject

Creates the answer if valid.

Broadcasts :ok if successful, :invalid otherwise.



17
18
19
20
21
22
23
24
25
# File 'app/commands/decidim/meetings/create_answer.rb', line 17

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

  transaction do
    answer_question
  end

  broadcast(:ok)
end