Class: Studies::DocumentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject


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

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


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


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

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

#newObject


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

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

#showObject


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

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