Class: StudyReportsController

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

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


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/study_reports_controller.rb', line 17

def create
  study = Study.find_by(id: params[:study_report][:study])
  study_report = StudyReport.create!(study: study, user: @current_user)

  study_report.schedule_report

  respond_to do |format|
    if study_report
      flash[:notice] = 'Report being generated'
      format.html { redirect_to(study_reports_path) }
      format.xml  { render xml: study_report, status: :created, location: study_report }
      format.json { render json: study_report, status: :created, location: study_report }
    else
      flash[:error] = 'Error: report not being generated'
      format.html { redirect_to(study_reports_path) }
      format.xml  { render xml: flash[:error], status: :unprocessable_entity }
      format.json { render json: flash[:error], status: :unprocessable_entity }
    end
  end
end

#indexObject


7
8
9
10
# File 'app/controllers/study_reports_controller.rb', line 7

def index
  @study_reports = StudyReport.order(id: :desc).page(params[:page])
  @studies = Study.alphabetical
end

#newObject


12
13
14
15
# File 'app/controllers/study_reports_controller.rb', line 12

def new
  params[:study_report] = { study: params[:study] }
  create
end

#showObject


38
39
40
41
42
43
# File 'app/controllers/study_reports_controller.rb', line 38

def show
  study_report = StudyReport.find(params[:id])
  send_data(study_report.report.read, type: 'text/plain',
                                      filename: "#{study_report.study.dehumanise_abbreviated_name}_progress_report.csv",
                                      disposition: 'attachment')
end