为什么我会收到“cache: [GET /] miss”在生产中使用 WebRick?
我无法使用 WebRick 在生产模式下测试我的网站,因为它会引发缓存错误。在开发和测试模式下一切都很完美。
我在 config/environments/production.rb 中设置了此选项:
config.serve_static_assets = true
然后我运行:
bundle exec rake assets:precompile
现在我启动服务器:
david$ rails s -e production
=> Booting WEBrick
=> Rails 3.2.1 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-01-31 19:52:35] INFO WEBrick 1.3.1
[2012-01-31 19:52:35] INFO ruby 1.9.3 (2011-10-30) [x86_64-darwin11.2.0]
[2012-01-31 19:52:35] INFO WEBrick::HTTPServer#start: pid=13329 port=3000
当我转到 http://localhost:3000 我得到“我们很抱歉,但出了点问题。”。在终端中,这就是它的输出:
cache: [GET /] miss
我在这里停滞不前。我不知道该怎么做。
I cannot test my website in production mode using WebRick, as it is raising cache errors. In development and testing modes everything works perfectly.
I have set this option in config/environments/production.rb:
config.serve_static_assets = true
And then I ran:
bundle exec rake assets:precompile
Now I start up the server:
david$ rails s -e production
=> Booting WEBrick
=> Rails 3.2.1 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-01-31 19:52:35] INFO WEBrick 1.3.1
[2012-01-31 19:52:35] INFO ruby 1.9.3 (2011-10-30) [x86_64-darwin11.2.0]
[2012-01-31 19:52:35] INFO WEBrick::HTTPServer#start: pid=13329 port=3000
And when I go to http://localhost:3000 I get "We're sorry, but something went wrong.". In the terminal this is what it outputs:
cache: [GET /] miss
I'm stalled here. I have no clue in what to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题在于资产管道,它必须在生产模式下进行良好配置,因为文件不会自动预编译。
就我而言,我插入了一个仅存在于一页中的 javascript 文件(带有
javascript_include_tag
),因此它未包含在 application.js 清单中。在这种情况下,资产管道在运行
assets:precompile
时不会预编译文件。为了包含丢失的文件,我们必须编辑 config/environments/Production.rb 并添加此行:
您会注意到此行已经存在,但已被注释。阅读评论以获取更多说明。如需了解更多信息,请参阅官方资产管道指南。
The problem is with the asset pipeline, which has to be well configured in production mode, as files are not precompiled automatically.
In my case, I was inserting a javascript file (with
javascript_include_tag
) that was only present in one page, so it was not included in the application.js manifest.In that case, the asset pipeline is not precompiling the file when running
assets:precompile
.In order to include the missing file, we have to edit
config/environments/production.rb
and add this line:You will notice that this line already exists, but it's commented. Read the comment for more clarification. For more info, look at the official asset pipeline guide.
有关丢失页面的消息发送 Rack::Cache 中间件。
如果您不需要在 Rails 应用程序中使用页面缓存,只需删除 config/application.rb 文件中的 Rack::Cache 即可:
This message about missing pages sends Rack::Cache middleware.
If you dont need to use page caching in your rails app, just remove Rack::Cache in config/application.rb file:
作为临时解决方案,以下内容对我来说很有效。
我更改了 config/environments/development.rb 文件,将 config.assets.compile 行从 false 更改为 true >
As provisional solution, the following made the trick for me.
I changed the
config/environments/production.rb
file to changeconfig.assets.compile
line fromfalse
totrue
要在生产环境中运行应用程序,这样就不会获得缓存:[GET /] miss
请检查您的 {project}/public 文件夹,是否存在任何资产文件夹
如果没有,则使用预编译资产
bundle exec rake assets:precompile
完成后
:在 production.rb 中将 config.assets.compile 设置为 true
然后在生产环境中重新启动 WebApp环境 。
这个方法对我有用,希望对你也有用。
如果您使用的是 Rails 3.2.0,您将得到 [GET /] miss ,但您的应用程序将正常工作。
To run application in production so you don't get cache: [GET /] miss
Please Check you {project}/public folder , is their any assets folder exists
if not then pre compile assets using
bundle exec rake assets:precompile
once this is done :
set config.assets.compile to true in production.rb
Then restart you WebApp in production environment .
This approch worked for me hope will work for you .
If you are using rails 3.2.0 you will get [GET /] miss , but your application will work properly .