Class: Studies::DocumentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

rubocop:todo Metrics/MethodLength



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/studies/documents_controller.rb', line 21

def create # rubocop:todo Metrics/MethodLength
  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



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

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



17
18
19
# File 'app/controllers/studies/documents_controller.rb', line 17

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

#showObject



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

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