我有一些项目可以在 /public
中的开发模式下正常访问。我的应用程序目录:favicon.ico
, robots.txt
.
我可以在开发中查看这些,例如localhost:3000/favicon.ico
.但是,当我推进生产时, Assets 在这些路径上不可见。结果,我没有收藏夹图标,谷歌也找不到我的 robots.txt 文件等等。
我该如何解决这个问题,以便 /public
目录是否可以通过相关网址访问?
最佳答案
在您的 app/config/environments/production.rb
中添加以下行
config.serve_static_assets = true
以下是 Rails Guides 所说的
config.serve_static_assets configures Rails itself to serve static assets. Defaults to true, but in the production environment is turned off as the server software (e.g. Nginx or Apache) used to run the application should serve static assets instead. Unlike the default setting set this to true when running (absolutely not recommended!) or testing your app in production mode using WEBrick. Otherwise you won´t be able use page caching and requests for files that exist regularly under the public directory will anyway hit your Rails app.
关于ruby-on-rails - Rails 公用文件夹项目在生产中不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22570563/