Class: Decidim::Admin::CreateAttachment
- Defined in:
- decidim-admin/app/commands/decidim/admin/create_attachment.rb
Overview
A command with all the business logic to add an attachment to a participatory process.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form, attached_to) ⇒ CreateAttachment
constructor
Public: Initializes the command.
Methods inherited from Command
call, #evaluate, #method_missing, #respond_to_missing?, #transaction
Constructor Details
#initialize(form, attached_to) ⇒ CreateAttachment
Public: Initializes the command.
form - A form object with the params. attached_to - The ActiveRecord::Base that will hold the attachment
12 13 14 15 |
# File 'decidim-admin/app/commands/decidim/admin/create_attachment.rb', line 12 def initialize(form, attached_to) @form = form @attached_to = attached_to 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 wasn't valid and we couldn't proceed.
Returns nothing.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'decidim-admin/app/commands/decidim/admin/create_attachment.rb', line 23 def call return broadcast(:invalid) if form.invalid? if @attachment.valid? @attachment.save! notify_followers broadcast(:ok) else @form.errors.add :file, @attachment.errors[:file] if @attachment.errors.has_key? :file broadcast(:invalid) end end |