Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

“cache: [GET /] miss” in production using WebRick #4807

Closed
ghost opened this issue Jan 31, 2012 · 8 comments
Closed

“cache: [GET /] miss” in production using WebRick #4807

ghost opened this issue Jan 31, 2012 · 8 comments

Comments

@ghost
Copy link

ghost commented Jan 31, 2012

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.

@kennyj
Copy link
Contributor

kennyj commented Feb 1, 2012

Did you see any problem in production.log ?

$ cat log/production.log

@ghost
Copy link
Author

ghost commented Feb 1, 2012

Nope, there are no updates when loading the page in production mode.

@kennyj
Copy link
Contributor

kennyj commented Feb 1, 2012

Umm..

I attempted to reproduce it , but I could not reproduce this issue.
It's work fine in production mode.

Please serve us a minimum app to reproduce this issue ?

@ghost
Copy link
Author

ghost commented Feb 1, 2012

@kennyj I think I have discovered the source of the problem: javascript_include_tag

If you delete the require_tree . statement from application.js and try to include one javascript file through javascript_include_tag you will get an error on production. The log will say that the file is not precompiled, even if you have precompiled it before.

Try it:

rails new testing -T
cd testing
rails g controller home index
rm public/index.html

Edit app/assets/javascripts/application.js and delete the line //= require_tree .

Edit app/views/home/index.html.erb and add this at the end:

<%= javascript_include_tag "home" %>

Edit config/routes.rb and replace get "home/index" with root :to => 'home#index'

Now precompile assets:

bundle exec rake assets:precompile

Run the server in development mode: rails s and go to http://localhost:3000/, then check the source code to see that the javascript file is correctly included:

<script src="/assets/home.js?body=1" type="text/javascript"></script>

Now stop the server and start it in production mode: rails s -e production, go to http://localhost:3000/ and you will get the "We're sorry, but something went wrong." error message.
The log/production.log says "home.js isn't precompiled".

@kennyj
Copy link
Contributor

kennyj commented Feb 1, 2012

Please edit config/environments/production.rb.

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

and precompile again.

@kennyj
Copy link
Contributor

kennyj commented Feb 1, 2012

It's work fine in my box... It's odd.
Please see the following command output.

$ ls -la public/assets/
合計 332
drwxrwxr-x 2 kennyj kennyj  4096  2月  2 00:39 .
drwxr-xr-x 3 kennyj kennyj  4096  2月  2 00:39 ..
-rw-rw-r-- 1 kennyj kennyj 99524  2月  2 00:28 application-3d7becb183603113a585f12ceec188fa.js
-rw-rw-r-- 1 kennyj kennyj 34925  2月  2 00:28 application-3d7becb183603113a585f12ceec188fa.js.gz
-rw-rw-r-- 1 kennyj kennyj     0  2月  1 21:09 application-95bd4fe1de99c1cd91ec8e6f348a44bd.css
-rw-rw-r-- 1 kennyj kennyj    20  2月  1 21:09 application-95bd4fe1de99c1cd91ec8e6f348a44bd.css.gz
-rw-rw-r-- 1 kennyj kennyj     0  2月  1 21:09 application.css
-rw-rw-r-- 1 kennyj kennyj    20  2月  1 21:09 application.css.gz
-rw-rw-r-- 1 kennyj kennyj 99524  2月  2 00:28 application.js
-rw-rw-r-- 1 kennyj kennyj 34925  2月  2 00:28 application.js.gz
-rw-rw-r-- 1 kennyj kennyj    28  2月  1 21:09 home-95f0ace38133acd0b2226f2c4181b3f3.js
-rw-rw-r-- 1 kennyj kennyj    48  2月  1 21:09 home-95f0ace38133acd0b2226f2c4181b3f3.js.gz
-rw-rw-r-- 1 kennyj kennyj    28  2月  1 21:09 home.js
-rw-rw-r-- 1 kennyj kennyj    48  2月  1 21:09 home.js.gz
-rw-rw-r-- 1 kennyj kennyj   238  2月  2 00:39 manifest.yml
-rw-r--r-- 1 kennyj kennyj  6646  2月  1 21:04 rails-782b548cc1ba7f898cdad2d9eb8420d2.png
-rw-r--r-- 1 kennyj kennyj  6646  2月  1 21:04 rails.png

$ cat public/assets/manifest.yml
---
rails.png: rails-782b548cc1ba7f898cdad2d9eb8420d2.png
application.js: application-3d7becb183603113a585f12ceec188fa.js
home.js: home-95f0ace38133acd0b2226f2c4181b3f3.js
application.css: application-95bd4fe1de99c1cd91ec8e6f348a44bd.css

@ghost
Copy link
Author

ghost commented Feb 1, 2012

Thanks @kennyj, you are right, it works fine, I forgot to enable the serve_static_assets option.

@ghost ghost closed this as completed Feb 1, 2012
@xpepermint
Copy link

I have the same problem. What version do I have to use to fix it? I'm on Rails 3.2.1, Mac, Ruby 1.9.3.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants