Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-3.1webrick

Why do I get "cache: [GET /] miss" in production using WebRick?


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.


Solution

  • 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:

    config.assets.precompile += %w( script1.js )
    

    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.