Class: Decidim::Templates::Admin::UpdateTemplate
- Defined in:
- decidim-templates/app/commands/decidim/templates/admin/update_template.rb
Overview
Updates the questionnaire template given form data.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(template, form, user) ⇒ UpdateTemplate
constructor
Initializes the command.
Methods inherited from Command
call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events
Constructor Details
#initialize(template, form, user) ⇒ UpdateTemplate
Initializes the command.
template - The Template to update. form - The form object containing the data to update. user - The user that updates the template.
13 14 15 16 17 |
# File 'decidim-templates/app/commands/decidim/templates/admin/update_template.rb', line 13 def initialize(template, form, user) @template = template @form = form @user = user end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Decidim::Command
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if the form was not valid and we could not proceed.
Returns nothing.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'decidim-templates/app/commands/decidim/templates/admin/update_template.rb', line 25 def call return broadcast(:invalid) unless @form.valid? return broadcast(:invalid) unless @user.organization == @template.organization @template = Decidim.traceability.update!( @template, @user, name: @form.name, description: @form.description ) broadcast(:ok, @template) end |