What Is New in Ruby on Rails 3.2
| Category | Highlights |
|---|---|
| New Features | Faster development mode with class-reloading on change, Journey routing engine, Automatic EXPLAIN for slow queries, TaggedLogging, ActiveRecord::Relation#explain, store, pluck, uniq, first_or_create, with_lock. |
| Improvements | Configurable log tags, auto_explain_threshold_in_seconds, reload_classes_only_on_change flag, exceptions_app middleware, DebugExceptions middleware, scaffold 204 responses for API, richer generators (indexes, uniq, decimal precision). |
| Bug Fixes | Fixed MIME type guessing for send_file, corrected CSRF token warning level, improved send_file MIME detection, fixed mass_assignment_sanitizer behavior, addressed Ruby 1.8.7 marshalling bugs in REE. |
| Breaking Changes | Requires Ruby ≥ 1.8.7 (1.9.2 recommended), vendor/plugins deprecated (removed in Rails 4.0), Rails::Plugin removed, set_table_name and related setters deprecated, default charset moved to config.action_dispatch.default_charset. |
| Deprecations | Rails::Plugin, vendor/plugins, ActionController::UnknownAction, ActionController::DoubleRenderError, method_missing for actions, old plugin generator, old config.paths API, set_table_name family, implicit layout lookup, render :template format/handler syntax. |
How does Rails 3.2 improve development speed and routing?
Rails 3.2 makes the development environment noticeably faster by reloading classes only when the underlying files change.
- Class reloading is driven by
config.reload_classes_only_on_change; set it tofalseto revert to the old eager reload. - The new Journey routing engine speeds up route recognition, which is especially visible in large apps with many routes.
- Development mode now logs the query plan for any query that exceeds
config.active_record.auto_explain_threshold_in_seconds(default 0.5 s).
In practice, teams see a 30-40 % reduction in request latency while working locally, and the faster route lookup reduces console startup time for rake routes.
What new Active Record features does Rails 3.2 add for query performance and convenience?
Rails 3.2 adds several Active Record helpers that let you diagnose and optimise queries without leaving the console.
- Automatic EXPLAIN: Queries slower than the threshold automatically call
explainand log the plan. - Relation#explain: Manually invoke
Model.where(...).explainto see the underlying SQL plan. - #pluck: Retrieves a single column directly from the DB, e.g.
Client.where(active: true).pluck(:id). - #uniq: Generates
SELECT DISTINCTqueries, e.g.Client.select(:name).uniq. - #first_or_create / #first_or_initialize: Clearer alternatives to the old dynamic
find_or_create_bymethods. - #with_lock: Wraps a pessimistic lock in a transaction, simplifying safe concurrent updates.
- store: Provides a simple key/value column for JSON-like data without a separate table.
These helpers reduce the amount of custom SQL you need to write and make it easier to catch missing indexes before they become production bottlenecks.
How does Rails 3.2 enhance logging and debugging for production applications?
Rails 3.2 introduces TaggedLogging and configurable log tags to make log lines more searchable.
- Enable tags in
config.log_tags = [:subdomain, :uuid]and Rails will prepend each line with the subdomain and request UUID. - The new
ActiveSupport::TaggedLoggingworks with the existingRails.loggerand respectsconfig.log_level. config.active_record.mass_assignment_sanitizer = :strictraises an exception on unsafe mass-assignment, surfacing bugs early.- The
DebugExceptionsmiddleware replaces parts ofShowExceptions, giving you a cleaner error page and easier hook for custom error handling viaconfig.exceptions_app.
In production, tagging logs with request IDs makes it trivial to trace a single request across multiple services, and the stricter mass-assignment checks reduce security regressions.
What are the major deprecations and breaking changes developers must address when upgrading to Rails 3.2?
Rails 3.2 removes several legacy APIs that will break older applications if not updated.
- Ruby version requirement raised to ≥ 1.8.7; Ruby 1.9.1 segfaults, so upgrade to 1.9.2 or later.
vendor/pluginsis deprecated; move plugins to gems or place them underlib/with an initializer.Rails::Pluginand the oldrails generate plugincommand are removed; userails plugin newinstead.- Setter methods like
set_table_name,set_primary_key, etc., are deprecated in favor ofself.table_name =style assignments. - Implicit layout lookup when a parent controller defines a layout is gone; explicitly set
layout nilif you need the old behavior. - ActionController::UnknownAction and DoubleRenderError are replaced by their AbstractController equivalents.
Watch out for these changes early in the upgrade cycle; most teams spend a day refactoring plugins and updating model declarations.
Frequently Asked Questions
Do I need to upgrade Ruby before moving to Rails 3.2?
Yes, Rails 3.2 requires Ruby 1.8.7 or newer; Ruby 1.9.2 is recommended for best compatibility.
How can I enable automatic query EXPLAIN in development?
Set config.active_record.auto_explain_threshold_in_seconds = 0.5 in config/environments/development.rb.
What is the recommended way to replace a vendor/plugin?
Extract the plugin into a gem and add it to your Gemfile, or move the code under lib/ and require it via an initializer.
Can I still use the old rails generate plugin command?
No, the old command is removed; use rails plugin new to create a new plugin.
How do I tag logs with the request UUID?
Add config.log_tags = [:uuid] to the appropriate environment file.
What code example creates a scoped migration for an engine?
Run rake db:migrate SCOPE=blog to migrate only the blog engine's migrations.