Skip to content

Instantly share code, notes, and snippets.

@patrickberkeley
Created January 3, 2009 06:53
Show Gist options
  • Select an option

  • Save patrickberkeley/42810 to your computer and use it in GitHub Desktop.

Select an option

Save patrickberkeley/42810 to your computer and use it in GitHub Desktop.
<%= link_to document.file.original_filename.parameterize, {:controller => 'documents', :action => 'show', :args => [:document => document.file.url(:original)]}, :class => 'document' %>
def show
path = File.join '../../public', params[:args]
logger.info(path)
render(:text => 'File not found', :status => 404) and return unless File.exists?(path) and ! File.directory?(path)
send_file path
end
Processing DocumentsController#show (for 127.0.0.1 at 2009-01-04 00:28:27) [GET]
Session ID: 9c5cc524691cbbc77d96e56547a8c029
Parameters: {"args"=>["document=%2Fsystem%2Ffiles%2F58%2Foriginal%2FrouterConfig.txt%3F1231048011"], "action"=>"show", "controller"=>"documents"}
../../public/document=%2Fsystem%2Ffiles%2F58%2Foriginal%2FrouterConfig.txt%3F1231048011
Completed in 11ms (View: 0, DB: 1) | 404 Not Found [http://mysite.local/documents/document=%252Fsystem%252Ffiles%252F58%252Foriginal%252FrouterConfig.txt%253F1231048011]
map.document 'documents/*args', :controller => 'documents', :action => 'show'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment