Rails 3 caching views in development mode

February 10, 2011

We are working with a Rails 3 port of Fat Free CRM. We have so many plugins modifying classes that we have to set config.cache_classes to true. But all our view templates seemed to stay cached as well, and I had to restart the server each time I made a change to a template. I couldn’t really explain why this was happening, and after a lot of searching I came across this Rails LightHouse ticket.

We just needed to add this to the end of our environments/development.rb file to clear the view template cache after every request:

ActiveSupport.on_load(:after_initialize) do
  ActionController::Base.before_filter do
    ActionController::Base.view_paths.each(&:clear_cache)
  end
end

Thanks to Eric for this.