Class: StudyReportsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- StudyReportsController
- Defined in:
- app/controllers/study_reports_controller.rb
Constant Summary
Constants included from FlashTruncation
FlashTruncation::STRING_OVERHEAD
Instance Method Summary collapse
-
#create ⇒ Object
rubocop:todo Metrics/AbcSize, Metrics/MethodLength.
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
Methods inherited from ApplicationController
#block_api_access, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!
Methods included from FlashTruncation
#max_flash_size, #truncate_flash, #truncate_flash_array
Instance Method Details
#create ⇒ Object
rubocop:todo Metrics/AbcSize, Metrics/MethodLength
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/study_reports_controller.rb', line 27 def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength 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 |
#index ⇒ Object
8 9 10 11 |
# File 'app/controllers/study_reports_controller.rb', line 8 def index @study_reports = StudyReport.order(id: :desc).page(params[:page]) @studies = Study.alphabetical end |
#new ⇒ Object
22 23 24 25 |
# File 'app/controllers/study_reports_controller.rb', line 22 def new params[:study_report] = { study: params[:study] } create end |
#show ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/study_reports_controller.rb', line 13 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 |