tags:

views:

151

answers:

2

To return a file using sinatra, I had been using this:

  get '/:name' do
    x = File.open('c:/mywebsite/' + params[:name],'r')
  end

where the incoming url is "http://localserver:4567/myfile.html.

It works, but it occurs to me there must be a better way, yet I can't find the preferred mechanism on the sinatra site.

+8  A: 

put static files in the public/ folder within the app's directory

Static Files

Static files are served from the ./public directory. You can specify a different location by setting the :public option:

set :public, File.dirname(__FILE__) + '/static'

Note that the public directory name is not included in the URL. A file ./public/css/style.css is made available as example.com/css/style.css.

from: http://www.sinatrarb.com/intro.html

statenjason
+2  A: 

Is this a static file? If so, I'd put it in the application's public directory. You can read more about static files here (scroll about a quarter of the way down the page to find the section marked "Static Files").

mipadi