views:

577

answers:

2

I am using Passenger and Rails' :cache => true to cache all my css into one big file. Deploys are done via Capistrano.

Now sometimes(!), the mem-generated all.css file can't be found after the app is restarted (and I get an error in the log)

ActionController::RoutingError (No route matches "/stylesheets/all.css" with {:method=>:get}):
  passenger (2.2.2) lib/phusion_passenger/rack/request_handler.rb:81:in `process_request'
  passenger (2.2.2) lib/phusion_passenger/abstract_request_handler.rb:203:in `main_loop'

Placing another restart.txt file manually or a cap deploy:restart will resolve the issue.

It's not a big thing, but it's always tedious to check and fix. Anybody has an idea what I am doing wrong?

Edit

My deploy:restart looks like this (exactly what I am doing manually).

desc "Restarting mod_rails with restart.txt"
task :restart, :roles => :app, :except => { :no_release => true } do
  run "touch #{current_path}/tmp/restart.txt"
end

Also I am not using any special (external) CSS files in my caching.

<%= stylesheet_link_tag "clear", "application", "contracts", :cache => true %>
+1  A: 

At the end of your deploy you should be running (as part of the deploy:restart task):

touch tmp/restart.txt

This will let Passenger know it needs to reload the Rails stack for the new code, and the new stylesheets will get cached upon the first request.

What does your current deploy:restart task look like?

bensie
I would also recommend updating Passenger to 2.2.5 for good measure. 2.2.2 was released back in April and it's continually under development with a few solid releases since then.
bensie
I included the listing - it's as you would recommend the `touch`. I might use this evening to upgrade the production server to 2.2.5 and see if this helps on the issue.
Marcel J.
+1  A: 

This specific issue is caused when the list of stylesheets with the cache option contains at least one external stylesheet. It happens only the very first time the app is started.

stylesheet_link_tag "foo.css", "/bar.css", "http://example.org/file.css", :cache => true
# crash
stylesheet_link_tag "foo.css", "/bar.css", :cache => true
# OK
Simone Carletti
Never even knew that one could use external CSS files in caching. However it's not the case in my situation.
Marcel J.