Sinatra:提供普通旧文件的正确方法是什么?

发布于 2024-08-20 16:14:32 字数 134 浏览 2 评论 0原文

这确实有效,但这是在黑暗中进行的尝试。我对鲁比了解不多。

为给定资源提供普通旧文件的公认方法是什么?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月下伊人醉 2024-08-27 16:14:32

您可以使用 set :public 指定静态文件的目录。然后,您可以使用 send_file() 提供文件,例如:

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

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 
梦年海沫深 2024-08-27 16:14:32

从 ./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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文