Configuring Rails CSS Caching with Passenger
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 :resta开发者_开发问答rt, :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 %>
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?
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
精彩评论