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

(Tuis.) #1
RailTies | 75

TimeZone


Instances ofTimeZoneare value objects*representing a particular time zone (an offset from
UTC and a name). They are used to perform conversions between different time zones:


Time.now # => Thu Oct 25 00:10:52 -0500 2007
# UTC-05
TimeZone[-5].now # => Thu Oct 25 00:10:52 -0500 2007
TimeZone[-5].adjust(1.month.ago) # => Tue Sep 25 00:10:52 -0500 2007

RailTies


RailTies is the set of components that wire together ActiveRecord, ActionController,
and ActionView to form Rails. We will examine the two most important parts of
RailTies: how Rails is initialized and how requests are processed.


Rails Configuration


TheRails::Configurationclass, defined ininitializer.rb, holds the configuration
attributes that control Rails. It has several general Rails attributes defined as
attributes on theConfigurationclass, but there is a little cleverness in the framework
class stubs. The five class stubs (action_controller,action_mailer,action_view,
active_resource, andactive_record) act as proxies to the class attributes of their
respectiveBase classes. In this way, the configuration statement:


config.action_controller.perform_caching = true

is the same as:


ActionController::Base.perform_caching = true

except with a unified configuration syntax.


Application Initialization in 20 Easy Steps


initializer.rb


Rails::Initializeris the main class that handles setting up the Rails environment
within Ruby. Initialization is kicked off byconfig/environment.rb, which contains the
block:


Rails::Initializer.run do |config|
# (configuration)
end

*Avalue objectis an object representing a value, whose identity is defined by that value only. In other words,
two objects compare as equal if and only if they have the same state.

Free download pdf