| Class | Mw::FileComponentController |
| In: |
components/mw/file_component_controller.rb
|
| Parent: | ApplicationController |
File component sends files to the user.
Example:
class BooksController < Application
....
def pdf
render_component :controller => 'mw/FileComponent',
:action => 'download',
:params => { :file => @params[:id] }
end
end
# File components/mw/file_component_controller.rb, line 31
31: def download
32: @file = Document.find(@params[:file])
33: @headers['Date'] = Time.now.rfc822
34: @headers['Expires'] = (Time.now + 360000).rfc822
35: @headers['Last-Modified'] = (@file.changed || Time.now).rfc822
36: @headers['Cache-Control'] = "public, max-age=3600"
37: filename = sane_filename(@file.title)
38: render_inline(@file.data, @file.content_type, filename)
39: end