This class provides an interface for dispatching a CGI (or CGI-like) request to the appropriate controller and action. It also takes care of resetting the environment (when Dependencies.load? is true) after each request.

Methods
D
R
T
Attributes
[RW] dispatch_hook
[RW] raise_exception
[RW] time_to_sleep
Class Public methods
dispatch(cgi = nil, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, output = $stdout)

Dispatch the given CGI request, using the given session options, and emitting the output via the given output. If you dispatch with your own CGI object be sure to handle the exceptions it raises on multipart requests (EOFError and ArgumentError).

# File rails/railties/lib/dispatcher.rb, line 35
def dispatch(cgi = nil, session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, output = $stdout)
  controller = nil
  if cgi ||= new_cgi(output)
    request, response = ActionController::CgiRequest.new(cgi, session_options), ActionController::CgiResponse.new(cgi)
    prepare_application
    controller = ActionController::Routing::Routes.recognize(request)
    controller.process(request, response).out(output)
  end
rescue Exception => exception  # errors from CGI dispatch
  failsafe_response(output, '500 Internal Server Error', exception) do
    controller ||= (ApplicationController rescue ActionController::Base)
    controller.process_with_exception(request, response, exception).out(output)
  end
ensure
  # Do not give a failsafe response here.
  reset_after_dispatch
end
reset_application!()

Reset the application by clearing out loaded controllers, views, actions, mailers, and so forth. This allows them to be loaded again without having to restart the server (WEBrick, FastCGI, etc.).

# File rails/railties/lib/dispatcher.rb, line 56
def reset_application!
  ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)

  Dependencies.clear
  ActiveSupport::Deprecation.silence do # TODO: Remove after 1.2
    Class.remove_class(*Reloadable.reloadable_classes)
  end
    
  ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
end
to_prepare(identifier = nil, &block)

Add a preparation callback. Preparation callbacks are run before every request in development mode, and before the first request in production mode.

An optional identifier may be supplied for the callback. If provided, ::to_prepare may be called again with the same identifier to replace the existing callback. Passing an identifier is a suggested practice if the code adding a preparation block may be reloaded.

# File rails/railties/lib/dispatcher.rb, line 75
def to_prepare(identifier = nil, &block)
  unless identifier.nil?
    callback = preparation_callbacks.detect { |ident, _| ident == identifier }

    if callback # Already registered: update the existing callback
      callback[-1] = block
      return
    end
  end

  preparation_callbacks << [identifier, block]

  return
end