Class: Decidim::Budgets::Admin::UpdateProject

Inherits:
Command
  • Object
show all
Includes:
AttachmentMethods, GalleryMethods
Defined in:
app/commands/decidim/budgets/admin/update_project.rb

Overview

This command is executed when the user changes a Project from the admin panel.

Instance Method Summary collapse

Constructor Details

#initialize(form, project) ⇒ UpdateProject

Initializes an UpdateProject Command.

form - The form from which to get the data. project - The current instance of the project to be updated.



16
17
18
19
20
# File 'app/commands/decidim/budgets/admin/update_project.rb', line 16

def initialize(form, project)
  @form = form
  @project = project
  @attached_to = project
end

Instance Method Details

#callObject

Updates the project if valid.

Broadcasts :ok if successful, :invalid otherwise.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/commands/decidim/budgets/admin/update_project.rb', line 25

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

  if process_gallery?
    build_gallery
    return broadcast(:invalid) if gallery_invalid?
  end

  transaction do
    update_project
    link_proposals
    create_gallery if process_gallery?
    photo_cleanup!
  end

  broadcast(:ok)
end