Class: LocationReportsController

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

Overview

This class handles creating and viewing Location Reports, which match up plates to their recorded physical location, and to their Studies and Faculty Sponser (can be multiple per plate). These reports are used by the Sample Management team to manage storage space in freezers and to locate old plates for return to their owners or disposal.

Instance Method Summary collapse

Methods inherited from ApplicationController

#block_api_access, #clean_params_from_check, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!

Instance Method Details

#createObject


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/location_reports_controller.rb', line 32

def create
  @location_report_form = LocationReport::LocationReportForm.new(location_report_params)
  @location_report_form.user = @current_user

  respond_to do |format|
    if @location_report_form.save
      flash[:notice] = I18n.t('location_reports.success')
      format.html { redirect_to location_reports_path }
    else
      error_messages    = @location_report_form.errors.full_messages.join('; ')
      flash.now[:error] = "Failed to create report: #{error_messages}"
      @location_reports = LocationReport.order(id: :desc).page(params[:page])
      format.html { render action: 'index' }
    end
  end
end

#indexObject


11
12
13
14
15
16
17
18
19
# File 'app/controllers/location_reports_controller.rb', line 11

def index
  @location_reports = LocationReport.order(id: :desc).page(params[:page])
  @location_report_form = LocationReport::LocationReportForm.new
  @location_report_form.user = @current_user

  respond_to do |format|
    format.html
  end
end

#showObject


21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/location_reports_controller.rb', line 21

def show
  @location_report = LocationReport.find(params[:id])

  send_data(
    @location_report.report.read,
    type: 'text/plain',
    filename: "location_report_#{@location_report.name}.csv",
    disposition: 'attachment'
  )
end