为什么我使用WebRick在生产中获得"cache:[GET /] miss"?

Dav*_*les 9 ruby-on-rails webrick ruby-on-rails-3 ruby-on-rails-3.1

我无法使用WebRick在生产模式下测试我的网站,因为它会增加缓存错误.在开发和测试模式中,一切都很完美.

我在config/environments/production.rb中设置了这个选项:

config.serve_static_assets = true
Run Code Online (Sandbox Code Playgroud)

然后我跑了:

bundle exec rake assets:precompile
Run Code Online (Sandbox Code Playgroud)

现在我启动服务器:

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
Run Code Online (Sandbox Code Playgroud)

当我去http:// localhost:3000时,我得到"我们很抱歉,但出了点问题." 在终端中,这是它输出的内容:

cache: [GET /] miss
Run Code Online (Sandbox Code Playgroud)

我在这里停滞不前.我不知道该怎么做.

Dav*_*les 5

问题在于资产管道,必须在生产模式下进行良好配置,因为文件不会自动预编译.

在我的情况下,我插入了一个javascript_include_tag只存在于一个页面中的javascript文件(with ),因此它没有包含在application.js清单中.

在这种情况下,资产管道在运行时不会预编译文件assets:precompile.

为了包含丢失的文件,我们必须编辑config/environments/production.rb并添加以下行:

config.assets.precompile += %w( script1.js )
Run Code Online (Sandbox Code Playgroud)

你会注意到这一行已经存在,但它被评论过了.阅读评论以获得更多说明.有关更多信息,请查看官方资产管道指南.