xyz
xyz

Reputation: 27837

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

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

Upvotes: 13

Views: 6245

Answers (2)

nstehr
nstehr

Reputation: 8138

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 

Upvotes: 16

Mark
Mark

Reputation: 108557

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

Upvotes: 4

Related Questions