Class: DocumentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

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



65
66
67
68
# File 'app/controllers/documents_controller.rb', line 65

def destroy
	@document.destroy
	redirect_to documents_path
end

#indexObject



40
41
42
# File 'app/controllers/documents_controller.rb', line 40

def index
	@documents = Document.all
end

#newObject



44
45
46
# File 'app/controllers/documents_controller.rb', line 44

def new
	@document = Document.new
end

#previewObject



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

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

#showObject



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

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



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

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