Sinatra:提供普通旧文件的正确方法是什么?
这确实有效,但这是在黑暗中进行的尝试。我对鲁比了解不多。
为给定资源提供普通旧文件的公认方法是什么?
get '/xyz' do
File.read 'abc.html'
end
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
set :public
指定静态文件的目录。然后,您可以使用send_file()
提供文件,例如:you can use
set :public
to specify the directory for your static files. Then, you can serve the file usingsend_file()
for example:从 ./public 目录中提供它。请参阅自述文件的静态文件部分和:static 和 :public 配置选项。
Serve it out of the ./public directory. See the Static Files section of the README and the :static and :public configuration options.