Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1
RailTies | 77

13.initialize_temporary_directories: Sets ActionController’s temporary session
and cache directories if they exist in the filesystem.
14.initialize_framework_settings: Transforms the framework-specific configura-
tion settings into method calls on the frameworks’Baseclasses. For example,
consider the configuration option:
config.active_record.schema_format = :sql
Theconfig.active_recordobject is an instance ofRails::OrderedOptions, which
is basically an ordered hash (ordered to keep the configuration directives in
order). During initialization, theinitialize_framework_settingsmethod trans-
forms it into the following:
ActiveRecord::Base.schema_format = :sql
This offers the advantage that the Configurationobject doesn’t have to be
updated every time a framework adds or changes a configuration option.
15.add_support_load_paths: Adds load paths for support functions. This function is
currently empty.
16.load_plugins: Loads the plugins from paths in theplugin_pathsconfiguration
item (defaultvendor/plugins). If apluginsconfiguration item is specified, load
those plugins respecting that load order. Plugins are loaded close to the end of
the process so that they can override any already loaded component.
17.load_observers: Instantiates ActiveRecord observers. This is done after plugins
so that plugins have an opportunity to modify the observer classes.
18.initialize_routing: Loads and processes the routes. Also sets the controller
paths from thecontroller_paths configuration item.
19.after_initialize: Calls any user-definedafter_initializecallback. These call-
backs are defined in the configuration block byconfig.after_initialize {...}.
20.load_application_initializers: Loads all Ruby files inRAILS_ROOT/config/
initializersand any of its subdirectories. Old framework initialization that may
previously have been contained inconfig/environment.rbcan now properly be
broken out into separate initializers.

Now the framework is ready to receive requests.


Request Dispatch


dispatcher.rb,fcgi_handler.rb,webrick_server.rb


TheDispatcherclass is the outside world’s interface to Rails. Web servers dis-
patch a request to Rails by callingDispatcher.dispatch(cgi,session_options,
output). Rails processes the given CGI request and presents the output to the
given location (which defaults to standard output). Rails can be reset by calling
Dispatcher.reset_application! to process multiple requests.

Free download pdf