31

What is the correct way to route your request through Sinatra so that it serves up the file with no processing? I'm looking for the most common way people do this in the Sinatra framework? I normally place all of my static content in a "content" path.

examples:
/content/css
/content/img
/content/js

How can I use a wildcard to serve up everything under content?

I was surprised there were no real examples of this here:
http://sinatra-book.gittr.com/

BuddyJoe
  • 69,735
  • 114
  • 291
  • 466

2 Answers2

54

Sinatra and Rails use the path public for static content - e.g., ./public/javascripts/. All files in these paths would then be served by the web server (e.g. Thin, Passenger), but without the need for /public in the URL (e.g. the file at #{my_app_root}/public/javascripts/application.js would be available via the Web at the URL http://#{my_domain}/javascripts/application.js).

yfeldblum
  • 65,165
  • 12
  • 129
  • 169
  • 3
    so this public folder should sit next to my views folder - at the same peer level? where would I learn things like this on the web? any good ref sites you can point me to? +1 – BuddyJoe Aug 16 '10 at 14:03
  • Not sure how I missed that. Thanks. – BuddyJoe Aug 16 '10 at 17:31
10
get '/notes/images/:file' do
  send_file('/root/dev/notes/images/'+params[:file], :disposition => 'inline')
end
smenon
  • 119
  • 2
  • 3