tags:

views:

243

answers:

2

This works, but it was a stab in the dark. I know little Ruby.

What's the accepted way to serve a plain old file for a given resource?

get '/xyz' do
    File.read 'abc.html'
end
+1  A: 

Serve it out of the ./public directory. See the Static Files section of the README and the :static and :public configuration options.

Mark
How would it know to map /xyz to abc.html with :static? Is File.read the right way to output a named file?
frou
Ahh, I misunderstood. If you configure a :public and want abc.html than point at http://webserver/abc.html and sinatra won't route it'll just serve the html. If you want to custom route and serve a static file, I think nstehr has got it. Of course you could also just name your abc.html to xyz (or symlin) in your public directory, but I still think I like nstehr's way.
Mark
I learned something anyway :)
frou
+4  A: 

you can use set :public to specify the directory for your static files. Then, you can serve the file using send_file() for example:

    get '/static_file' do
      send_file('my_static_file')
   end 
nstehr