What Is New in Ruby on Rails 3.1
| Category | Highlights |
|---|---|
| New Features | Asset Pipeline (Sprockets), HTTP Streaming support, jQuery as default JS library, Identity Map (off by default), ParamsWrapper enabled for JSON, config.force_ssl middleware, Rack::Cache and Rack::ETag in default stack, engines can be mounted anywhere, rails plugin new command. |
| Improvements | Asset pipeline configuration (compress, debug, digest), generators create CoffeeScript and Sass stubs, scaffold JSON format, http_basic_authenticate_with helper, form_for accepts method option directly, SafeBuffer mutation prohibited, HTML5 button_tag, data-* attribute generation, improved logging to STDOUT. |
| Breaking Changes | Requires Ruby ≥ 1.8.7 (1.9.2 recommended), RJS config removed, :cache and :concat options in asset helpers are ignored, auto_link extracted to external gem, rhtml/rxml template handlers removed, CSV fixtures deprecated, association destroy semantics changed, default jQuery gem must be added, config.action_dispatch.x_sendfile_header defaults to nil. |
| Deprecations | CSV fixtures, auto_link gem, rhtml/rxml handlers, old-style hash generation (still works but discouraged). |
How does the new Asset Pipeline change asset management in Rails 3.1?
The Asset Pipeline introduces a unified, pre-processing pipeline for CSS, JavaScript, and images, powered by Sprockets.
All assets live under app/assets, lib/assets or vendor/assets. You declare dependencies with directives such as //= require jquery in application.js or *= require_tree . in application.css. During deployment, rake assets:precompile concatenates, minifies and fingerprints files, producing digested URLs like /assets/application-3f2c1e9c.css.
Configuration lives in config/application.rb and the environment files:
# config/application.rb
config.assets.enabled = true
config.assets.version = '1.0'
# config/environments/production.rb
config.assets.compress = true
config.assets.digest = true
config.assets.compile = false
In practice, this means you no longer need to manually manage cache-busting query strings or hand-roll concatenated files; the pipeline does it for you.
Why is jQuery the default JavaScript library in Rails 3.1?
Rails 3.1 ships with the jquery-rails gem and the application generator automatically includes jquery and jquery_ujs in the asset manifest.
To switch back to Prototype you can run rails new myapp -j prototype or replace the gems in the Gemfile. The new default reflects the broader community adoption of jQuery and provides unobtrusive JavaScript helpers out of the box.
Typical app/assets/javascripts/application.js now looks like:
//= require jquery
//= require jquery_ujs
//= require_tree .
This matters if your existing codebase relies on Prototype helpers; you'll need to update selectors and remote forms accordingly.
What is HTTP Streaming and when should I enable it?
HTTP Streaming lets the server begin sending the response body while still generating the rest of the page, reducing perceived latency for large pages.
It is opt-in, requires Ruby 1.9.2 or newer, and needs a web server that supports streaming (e.g., NGINX with Unicorn). Enable it per-controller with stream or by using ActionController::Live in Rails 3.1.
class PostsController < ActionController::Base
stream
def index
response.stream.write "Chunk 1"
# heavy processing ...
response.stream.write "Chunk 2"
response.stream.close
end
end
Use streaming for dashboards, long-polling APIs, or any endpoint where early data delivery improves user experience.
What breaking changes should I watch for when upgrading to Rails 3.1?
Several APIs were removed or altered, so you need to adjust your code before the upgrade.
- Ruby version must be ≥ 1.8.7; Ruby 1.9.1 segfaults, so upgrade to 1.9.2.
- RJS configuration (
config.action_view.debug_rjs) is gone; remove it fromdevelopment.rb. - Asset helper options
:cacheand:concatare ignored; delete them from view helpers. - CSV fixtures are deprecated and will disappear in 3.2; migrate to YAML or factories.
- Auto-link helper was extracted; add the
rails_autolinkgem if you still need it. - rhtml and rxml template handlers were removed; use ERB, Haml, or Slim instead.
- Association
destroynow only removes join-table rows forhas_and_belongs_to_manyandhas_many :through; update any code that relied on the old behavior. - Default
config.action_dispatch.x_sendfile_headeris nil; configure it per server if you use X-Sendfile.
Most teams will need to run their test suite after these changes; the asset pipeline will also surface missing assets early.
Frequently Asked Questions
Does upgrading to Rails 3.1 require a newer Ruby version?
Yes Rails 3.1 requires Ruby 1.8.7 or higher and works best with Ruby 1.9.2.
How do I enable the Asset Pipeline in an existing Rails 3 app?
Add config.assets.enabled = true and config.assets.version = '1.0' to config/application.rb and include sass-rails, coffee-rails and uglifier gems in the Gemfile.
What gem replaces Prototype as the default JavaScript library?
The jquery-rails gem provides jQuery and the unobtrusive JavaScript adapters.
How can I force all requests to use HTTPS in Rails 3.1?
Set config.force_ssl = true in the appropriate environment configuration file.
Are CSV fixtures still supported in Rails 3.1?
No CSV fixtures are deprecated and will be removed in Rails 3.2.
How do I simplify basic HTTP authentication in controllers?
Use http_basic_authenticate_with name: "dhh", password: "secret", except: :index.