Class: Decidim::Consultations::Admin::UpdateQuestionConfiguration

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

Overview

A command that configures how many and how much questions can be voted.

Instance Method Summary collapse

Constructor Details

#initialize(question, form) ⇒ UpdateQuestionConfiguration

Public: Initializes the command.

question - the Question to update form - A form object with the params.


12
13
14
15
# File 'decidim-consultations/app/commands/decidim/consultations/admin/update_question_configuration.rb', line 12

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

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the form wasn't valid and we couldn't proceed.

Returns nothing.


23
24
25
26
27
28
29
30
31
32
33
34
# File 'decidim-consultations/app/commands/decidim/consultations/admin/update_question_configuration.rb', line 23

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

  # We don't have other question fields in this forms so any additional
  # validation error will be just shown in a flash message
  begin
    update_question!
    broadcast(:ok, question)
  rescue StandardError => e
    broadcast(:invalid, question, e.message)
  end
end