What Is New in Ruby on Rails 3.0
| Category | Highlights |
|---|---|
| New Features | Application object (config/application.rb), script/rails command, Bundler/Gemfile, Active Model abstraction, AbstractController, Arel integration, Mail gem extraction, Action Dispatch router. |
| Improvements | Unified generators API, hookable Railties, default HTML5 output, automatic HTML escaping, built-in CSRF protection, responder pattern, I18n enhancements, optional edge/dev flags for rails new. |
| Breaking Changes | Ruby 1.8.7+ required, removal of config.gem, script/* scripts replaced, rake freeze dropped, old routing DSL deprecated, RAILS_ROOT/RAILS_ENV constants removed. |
| Deprecations | config.gem, rake freeze, filter_parameter_logging, cookie_verifier_secret, RAILS_ROOT, RAILS_ENV, RAILS_DEFAULT_LOGGER, old map routing commands. |
How does Rails 3 change the way we configure and start a new application?
The first step is now to run rails new myapp, which generates a Gemfile and a config/application.rb Application object.
- All environment-specific settings live inside the Application object;
config/environment.rbis now a thin loader. - The old
script/scripts are gone;rails consoleandrails generatereplace them. - Dependencies are managed by Bundler. Run
bundle installto resolve theGemfileand you can vendor gems withbundle install --path vendor/bundle.
# Example Gemfile
source 'https://rubygems.org'
gem 'rails', '3.0.0'
gem 'pg'
gem 'puma'
In practice this means a cleaner, reproducible setup and eliminates the need for config.gem calls.
What are the major architectural shifts introduced in Rails 3?
Rails 3 decouples core components and introduces a unified plugin API via Railties.
- Railties rewrite: Generators, engines, and plugins now share a single API; you can place custom generators under
lib/templatesand hook into any stage. - Active Model: Provides a thin interface (validations, callbacks, naming) that any ORM can implement, allowing DataMapper or Sequel to plug into Action Pack.
- AbstractController: Extracts rendering, helpers, and callbacks from ActionController, enabling ActionMailer and other libraries to inherit the same base.
- Arel: Powers the new relation-based query interface; all Active Record queries now return an
Arel::Relationobject that can be chained. - Mail gem extraction: Email parsing and delivery are delegated to the standalone
mailgem, reducing ActionMailer's footprint.
Watch out for the compatibility layer: the old Active Record API still works but will be removed after Rails 3.1.
How has routing and controller handling been revamped in Rails 3?
Rails 3 introduces Action Dispatch, a Rack-based router with a modern DSL.
- Routes are defined inside
AppName::Application.routes do ... endinstead of the oldmapblock. - New helpers:
match,scope,constraints, androotsimplify complex routing scenarios. - Controllers now inherit from
ActionController::Basewhich itself inherits fromAbstractController::Base;protect_from_forgeryis enabled by default. - The responder pattern (
respond_withandActionController::Responder) streamlines format negotiation.
# config/routes.rb
MyApp::Application.routes do
root to: 'home#index'
resources :posts
match '/search', to: 'search#show', via: [:get, :post]
end
This matters if you rely on the legacy catch-all route; it is now commented out and will disappear in Rails 3.1.
What updates to Active Record and validations should I be aware of in Rails 3?
Active Record now returns chainable relations powered by Arel, and validations live in Active Model.
- New query methods:
where,select,order,limit, etc., all return anArel::Relationthat can be further chained. - Validations are available via
ActiveModel::Validations; the classicvalidates_presence_ofstill works, but you can also use the hash-stylevalidates :title, presence: true, length: { maximum: 50 }. - Custom validators are simple Ruby classes inheriting from
ActiveModel::EachValidator.
# app/models/post.rb
class Post < ActiveRecord::Base
validates :title, presence: true, length: { maximum: 100 }
validates :slug, uniqueness: true
end
In practice, the new API makes complex queries more readable and lets you swap the ORM without rewriting validation logic.
Which APIs were deprecated or removed in Rails 3 and what should I replace them with?
Rails 3 removes several legacy entry points and replaces them with modern equivalents.
- config.gem → use a
Gemfileand Bundler. - script/* →
railscommand (e.g.,rails console,rails server). - rake freeze →
bundle install --path vendor/bundleto vendor gems. - RAILS_ROOT / RAILS_ENV / RAILS_DEFAULT_LOGGER →
Rails.root,Rails.env,Rails.logger. - filter_parameter_logging →
config.filter_parameters << :passwordin an initializer. - old map routing → new DSL inside
Application.routeswithresources,match, etc.
Most teams will need to audit initializers, Rake tasks, and plugin code for these patterns before the upgrade.
Frequently Asked Questions
Can I still use Ruby 1.9.1 with Rails 3?
Rails 3 crashes on Ruby 1.9.1; you need Ruby 1.9.2 or later.
Do I have to rewrite all my models to use Active Model?
No, existing Active Record models continue to work unchanged.
How do I generate a scaffold in Rails 3?
Run rails generate scaffold Post title:string body:text and the new generators will create the files.
Is the old config.gem syntax still supported?
It has been removed; you must list gems in a Gemfile and run bundle install.
What command replaces rake freeze?
Use bundle install --path vendor/bundle to vendor your gems.
Will my existing Rake tasks still load automatically?
Tasks must now reside in lib/tasks; tasks in PLUGIN/tasks are no longer loaded.