If you include the following in your environment.rb, sessions will be disabled:
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:disabled => true)
This works wonderfully for requests that are processed normally through Rails' routing mechanism.
However, whenever there is an exception, such as a ActionController::RoutingError caused by a bad image URL, a session will be created. This results, in the default configuration, in a /tmp/ruby_sess.* file appearing.
This problem can be fixed by first changing the #dispatch method in Dispatcher (dispatcher.rb, line 36):
request, response = ActionController::CgiRequest.new(cgi, (session_options[:disabled] ? false : session_options)), ActionController::CgiResponse.new(cgi)
This causes CgiRequest to instantiate a Hash for @session instead of a CGI::Session.
The second part of the fix is with handling the exception page. The #process_with_exception method in ActionController::Rescue::ClassMethods should call #process_without_session_management_support instead of #process. Line 20 of rescue.rb becomes:
new.process_without_session_management_support(request, response, :rescue_action, exception)
Without this change, @session_options in the CgiRequest gets updated in #process_with_session_management_support with the results of #session_options_for and will no longer have a false value. Later, in #assign_shortcuts, #session in CgiRequest is queried and a CGI::Session object is instantiated because @session_options is not false.
And, yeah, this was a real nasty bug to find & fix :-)
-ch