Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sinatra: What's the correct way to serve a plain old file?

Tags:

ruby

sinatra

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
like image 228
xyz Avatar asked Feb 04 '10 22:02

xyz


2 Answers

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 
like image 170
nstehr Avatar answered Nov 30 '22 23:11

nstehr


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

like image 41
Mark Avatar answered Dec 01 '22 00:12

Mark