What Is New in Ruby on Rails 2.3
| Category | Highlights |
|---|---|
| New Features | Full Rack integration, revived Rails Engines, nested attributes & transactions, dynamic & default scopes, batch find methods, HTTP Digest authentication, unified render API, localized view templates. |
| Improvements | Middleware stack inspection (rake middleware), lazy-loaded sessions, 8% faster respond_to, per-request cache for remote stores, MIME::Type =~ operator, partial translation scoping. |
| Bug Fixes | Removed stray AS in HABTM preload, new_record? returns false, fixed table-name quoting in has_many :through, updated_at can be set manually, clearer find_by! errors, to_xml camelize option, callback cancellation fix, JDBC test tasks, validates_length_of custom messages, scoped count works, invalid? now mirrors valid?. |
| Breaking Changes | CGI layer removed (CgiRequest/Response gone), session stores renamed to ActionController::Session::*, config.session key renamed to :key and :session_domain to :domain, formatted_ route helpers deprecated, application.rb renamed to application_controller.rb, ActionController::Request now inherits from Rack::Request, middleware now handles request locking, ParamsParser added for JSON/XML/YAML. |
| Deprecations | Formatted_ route helpers, old CGI session classes, legacy render syntax requiring explicit :file/:template/:action options. |
How does the Rack integration in Rails 2.3 affect my existing application?
Rails 2.3 runs the entire stack on Rack, which means every request passes through a configurable middleware chain before reaching your controllers.
In practice this gives you three immediate benefits:
- You can swap the built-in WEBrick server for any Rack-compatible server (Thin, Puma, Unicorn) simply by running
script/serverwith aconfig.rufile. - The new
rake middlewaretask lets you inspect ordering, add custom middleware, or remove the defaultActionController::Lockif you manage concurrency elsewhere. - Session handling is now lazy-loaded and lives in Rack, so sessions are only touched when you actually read or write
sessionin your controller.
Watch out for code that directly accessed CgiRequest or relied on CGI-specific environment variables - those classes have been removed.
# Example: inserting a custom middleware
# config/initializers/custom_middleware.rb
Rails.application.config.middleware.insert_before ActionDispatch::Static, "MyAuthMiddleware"
What are the most important Active Record enhancements in Rails 2.3?
Rails 2.3 adds nested attributes, nested transactions, dynamic/default scopes, and batch find methods to make complex data workflows easier.
- Nested attributes let you save a parent and its children in one call:
accepts_nested_attributes_for :author, :pages. - Nested transactions use savepoints so you can roll back an inner block without aborting the outer one, e.g.
User.transaction { ... User.transaction(:requires_new => true) { ... raise ActiveRecord::Rollback } }. - Dynamic scopes generate methods on the fly (
Order.scoped_by_customer_id(12)) and default_scope applies a base ordering to every query. - Batch processing with
find_in_batchesandfind_eachreduces memory pressure when iterating over thousands of rows.
This matters if your app imports large CSV files or needs atomic updates across several associated models.
How have rendering and routing changed in Rails 2.3?
Rails 2.3 simplifies rendering by inferring the type of template from the string you pass to render, and it streamlines routing by dropping the old formatted_ helpers.
Examples:
# Old style
render :template => 'posts/show'
# New style
render 'posts/show'
Routing now accepts :format as a regular option, cutting route-generation time by roughly 50% and saving up to 100 MB of memory in large apps. You can also split routes across multiple files with RouteSet#add_configuration_file, which is handy for engines.
What should I know about session handling and middleware in Rails 2.3?
Sessions are now lazy-loaded and live in the Rack layer, meaning they are only instantiated when you reference session in a controller.
- Switching the session store is still done via
ActionController::Base.session_store = :active_record_store, but the underlying classes have been renamed (e.g.,ActionController::Session::CookieStore). - The mutex that once wrapped the whole request is now the
ActionController::Lockmiddleware, giving you finer control over concurrency. - Use
rake middlewareto verify thatActionDispatch::Session::CookieStore(or your chosen store) appears in the stack.
Most teams will see no functional change, but if you previously disabled sessions globally you can now simply avoid touching session and the overhead disappears.
Frequently Asked Questions
Do I need to change my existing routes after upgrading to Rails 2.3?
Most routes will continue to work, but you should replace any formatted_ helpers with the standard :format option for better performance.
Can I still use CGI with Rails 2.3?
Yes, Rails provides a CGIHandler wrapper that proxies CGI requests through Rack.
How do I list the current middleware stack?
Run rake middleware in the application root to see the ordered list of middleware components.
Is the new default_scope applied to all find calls?
Yes, default_scope adds its conditions to every query unless you explicitly override it with unscoped.
What is the syntax for enabling nested attributes on a model?
In the model file add accepts_nested_attributes_for followed by the association name, for example accepts_nested_attributes_for :author.
Will my existing session cookies break after the rename of session classes?
No, the cookie format stays the same; only the internal class names have changed.