Class: Decidim::Notify::UpdateNote
- Inherits:
-
Rectify::Command
- Object
- Rectify::Command
- Decidim::Notify::UpdateNote
- Defined in:
- app/commands/decidim/notify/update_note.rb
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form) ⇒ UpdateNote
constructor
Public: Initializes the command.
Constructor Details
#initialize(form) ⇒ UpdateNote
Public: Initializes the command.
form - A config form
9 10 11 |
# File 'app/commands/decidim/notify/update_note.rb', line 9 def initialize(form) @form = form end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if we couldn’t proceed.
Returns nothing.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/commands/decidim/notify/update_note.rb', line 19 def call return broadcast(:invalid) if form.invalid? begin note = Note.find(form.id) note. = Author.find_by(code: form.code, component: current_component)&.user note.body = form.body note.creator = current_user unless note.creator note.chapter = create_chapter note.save! broadcast(:ok, note, @new_chapter) rescue ActiveRecord::ActiveRecordError => e broadcast(:invalid, e.) end end |