Class: Studies::DocumentsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/studies/documents_controller.rb

Overview

rubocop:todo Style/Documentation

Instance Method Summary collapse

Instance Method Details

#createObject


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/studies/documents_controller.rb', line 17

def create
  document_settings = params[:document]
  document_settings[:documentable] = @study
  @document = Document.new(document_settings)
  begin
    if @document.save
      flash[:notice] = 'Document was saved okay'
      redirect_to [:admin, @study], status: 303
    else
      render action: 'new'
    end
  rescue ActiveRecord::StatementInvalid
    flash[:error] = 'Something bad happened. Perhaps karma has caught up with you?'
    redirect_to [:admin, @study], status: 303
  end
end

#destroyObject


39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/studies/documents_controller.rb', line 39

def destroy
  @document = Document.find(params[:id])
  if @document.destroy
    flash[:notice] = 'Document was successfully deleted'
    redirect_to [:admin, @study], status: 303
  else
    flash[:error] = 'Document cannot be destroyed'
    redirect_to [:admin, @study], status: 303
  end
end

#indexObject


8
9
10
11
# File 'app/controllers/studies/documents_controller.rb', line 8

def index
  @study = Study.find(params[:study_id])
  @documents = @study.documents
end

#newObject


13
14
15
# File 'app/controllers/studies/documents_controller.rb', line 13

def new
  @study = Study.find(params[:study_id])
end

#showObject


34
35
36
37
# File 'app/controllers/studies/documents_controller.rb', line 34

def show
  @document = Document.find(params[:id])
  send_data @document.current_data, filename: @document.filename, type: @document.content_type, disposition: 'inline'
end