Class: Decidim::ParticipatoryDocuments::Admin::AnswerSuggestion

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/participatory_documents/admin/answer_suggestion.rb

Instance Method Summary collapse

Constructor Details

#initialize(form, suggestion) ⇒ AnswerSuggestion

Public: Initializes the command.

form - A form object with the params.



10
11
12
13
# File 'app/commands/decidim/participatory_documents/admin/answer_suggestion.rb', line 10

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

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/commands/decidim/participatory_documents/admin/answer_suggestion.rb', line 15

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

  store_initial_suggestion_state

  suggestion.assign_attributes(attributes)
  if (%w(state answer answer_is_published) & suggestion.changed).any?
    transaction { answer_suggestion }
    notify_suggestion_answer
  end

  broadcast(:ok)
end