ruby-on-railscachingpassengermod-rails

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

Solution

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