Class: Decidim::Admin::CreateAttachment
- Inherits:
-
Command
- Object
- Command
- 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, user) ⇒ CreateAttachment
constructor
Public: Initializes the command.
Constructor Details
#initialize(form, attached_to, user) ⇒ 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 16 |
# File 'decidim-admin/app/commands/decidim/admin/create_attachment.rb', line 12 def initialize(form, attached_to, user) @form = form @attached_to = attached_to @user = user end |
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.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'decidim-admin/app/commands/decidim/admin/create_attachment.rb', line 24 def call return broadcast(:invalid) if form.invalid? if @attachment.valid? Decidim.traceability.perform_action!(:create, Decidim::Attachment, @user) do @attachment.save! notify_followers broadcast(:ok) @attachment end else @form.errors.add :file, @attachment.errors[:file] if @attachment.errors.has_key? :file broadcast(:invalid) end end |