Class: RepresentationStatusChangesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/representation_status_changes_controller.rb

Overview

Allows bulk changes of Representation statuses from the Representation index page

Instance Method Summary collapse

Instance Method Details

#createObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/representation_status_changes_controller.rb', line 4

def create
  status, representation_ids = representation_status_change_params.values_at(:status, :representation_ids)

  update_count = if status.present?
                   representation_ids = Array(representation_ids)

                   representations = current_organization.representations.where(id: representation_ids)
                   representations.each { |r| authorize(r) }

                   representations.update_all(status: status)
                   logger.info "Update Representation IDs #{representation_ids.to_sentence} to status '#{status}'"
                 else
                   logger.warn 'Did not update any representations since status was blank'
                   0
                 end

  redirect_back fallback_location: root_url, notice: "Set #{update_count} #{'description'.pluralize(update_count)} to status '#{status.titleize}'"
end