Class: DocumentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



46
47
48
49
50
51
52
53
# File 'app/controllers/documents_controller.rb', line 46

def create
	@document = Document.new(params[:document])
	@document.save!
	redirect_to preview_document_path(@document)
rescue ActiveRecord::RecordInvalid
	flash.now[:error] = "Error"
	render :action => 'new'
end

#destroyObject



63
64
65
66
# File 'app/controllers/documents_controller.rb', line 63

def destroy
	@document.destroy
	redirect_to documents_path
end

#indexObject



38
39
40
# File 'app/controllers/documents_controller.rb', line 38

def index
	@documents = Document.all
end

#newObject



42
43
44
# File 'app/controllers/documents_controller.rb', line 42

def new
	@document = Document.new
end

#previewObject



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

def preview
#		#	otherwise looks for template for pdf, jpg or whatever
#		params[:format] = 'html'
end

#showObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/documents_controller.rb', line 8

def show
	if @document.document.path.blank?
		flash[:error] = "Does not contain a document"
		redirect_to preview_document_path(@document)
	elsif @document.document.exists?
		#puts "Document exists!"
		if @document.document.options[:storage] == :filesystem #	&&
#				File.exists?(@document.document.path)
			#	basically development or non-s3 setup
			send_file @document.document.path
		else
			#puts "Storage is S3?"

#	Privacy filters are still not active
			#	basically a private s3 file
#				redirect_to @document.s3_url
			redirect_to @document.document.expiring_url

		end
	else
		flash[:error] = "Document does not exist at the expected location."
		redirect_to preview_document_path(@document)
	end
end

#updateObject



55
56
57
58
59
60
61
# File 'app/controllers/documents_controller.rb', line 55

def update
	@document.update_attributes!(params[:document])
	redirect_to preview_document_path(@document)
rescue ActiveRecord::RecordInvalid
	flash.now[:error] = "Error"
	render :action => 'edit'
end