Class: Decidim::ParticipatoryDocuments::CreateSuggestion

Inherits:
Command
  • Object
show all
Includes:
AttachmentMethods
Defined in:
app/commands/decidim/participatory_documents/create_suggestion.rb

Instance Method Summary collapse

Constructor Details

#initialize(form, suggestable) ⇒ CreateSuggestion

Returns a new instance of CreateSuggestion.



8
9
10
11
# File 'app/commands/decidim/participatory_documents/create_suggestion.rb', line 8

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

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/commands/decidim/participatory_documents/create_suggestion.rb', line 13

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

  begin
    transaction do
      create_suggestion
    end
    broadcast(:ok, suggestion)
  rescue ActiveRecord::RecordInvalid => e
    Rails.logger.info e.message
    broadcast(:invalid, e.message)
  end
end