Latest in branch 4.2
4.2.11.3
Released 15 May 2020
(6 years ago)
SoftwareRuby on Rails
Version4.2
Status
End of life
Initial release4.2.0
19 Dec 2014
(11 years ago)
Latest release4.2.11.3
15 May 2020
(6 years ago)
End of bug fixes30 Jun 2016
(Ended 9 years, 10 months ago)
End of security fixes27 Apr 2017
(Ended 9 years, 1 month ago)
Release noteshttps://github.com/rails/rails/releases/tag/v4.2.11.3
Source codehttps://github.com/rails/rails/tree/v4.2.11.3
Downloadhttps://github.com/rails/rails/releases/tag/v4.2.11.3
Ruby on Rails 4.2 ReleasesView full list

What Is New in Ruby on Rails 4.2

Category Highlights
New Features Active Job framework, deliver_later for Action Mailer, Web Console, foreign-key migration helpers, config.x custom namespace, Rails.application.config_for, bin/setup script
Improvements Adequate Record prepared-statement caching, automatic ETag digest inclusion, gzip asset serving, URL segment auto-escaping, always_permitted_parameters default
Breaking Changes render "foo/bar" now treats the string as a template, class-level respond_with moved to responders gem, rails server defaults to localhost, changed :status symbols, render nothing: true padding removed, filter method names deprecated
Deprecations respond_with / class-level respond_to, only_path option on *_path helpers, assert_tag family, deliver / deliver! in mailers, *_path helpers in mailers, swallowing errors in after_commit/after_rollback

How does Rails 4.2 simplify background job processing?

Rails 4.2 introduces Active Job, a single API that abstracts over Resque, Sidekiq, Delayed Job and other queuing back-ends.

Jobs are defined by subclassing ActiveJob::Base and can receive Active Record objects directly because Global ID serialises them as URIs.

class TrashableCleanupJob < ActiveJob::Base
  def perform(trashable, depth)
    trashable.cleanup(depth)
  end
end

Action Mailer now ships with deliver_later, which enqueues the email as an Active Job instead of sending it synchronously.

UserMailer.welcome_email(user).deliver_later

In practice this means you can add background processing to an existing app with a single gem change and no code rewrite.

What database performance and schema enhancements arrive in Rails 4.2?

Rails 4.2 adds Adequate Record, which caches common find and find_by queries as prepared statements, cutting the SQL generation overhead by up to 2×.

Post.find(1)   # first call creates the prepared statement
Post.find(2)   # subsequent call reuses it

The migration DSL now supports foreign keys for MySQL, MySQL2 and PostgreSQL, and these keys are dumped into schema.rb so they survive schema loading.

add_foreign_key :articles, :authors
remove_foreign_key :accounts, column: :owner_id

This matters if you rely on referential integrity at the database level or need the extra performance boost from prepared statements.

Which developer productivity tools are baked into new Rails 4.2 apps?

New Rails 4.2 applications include the Web Console gem, giving you an interactive Ruby console on every error page and a console helper for on-demand debugging.

The config.x namespace lets you store arbitrary configuration without polluting the main config namespace.

# config/environments/production.rb
config.x.payment_processing.schedule = :daily
config.x.payment_processing.retries  = 3

Rails 4.2 also adds Rails.application.config_for for loading environment-specific YAML files, and a bin/setup script that standardises project bootstrapping.

What are the key breaking changes you must address when upgrading to Rails 4.2?

Watch out for these upgrade-time gotchas:

  • render with a string argument now renders a template; use render file: "foo/bar" if you need to render a raw file.
  • respond_with and class-level respond_to have been removed; add gem "responders", "~> 2.0" to continue using them.
  • rails server now binds to localhost by default; start with rails server -b 0.0.0.0 to expose it on the network.
  • :status symbols have changed - :request_entity_too_large is now :payload_too_large, etc.
  • render nothing: true no longer adds a space; prefer head :ok for empty responses.
  • filter callbacks are deprecated in favour of *_action equivalents (e.g., before_action instead of before_filter).

Most teams can upgrade by running the test suite, fixing the above items, and adding the responders gem if needed.

Frequently Asked Questions

Do I need to add a new gem to keep using respond_with in Rails 4.2?
Yes you must add gem "responders", "~> 2.0" to your Gemfile.

How do I add a foreign key in a Rails 4.2 migration?
Use add_foreign_key :articles, :authors inside the change method.

What method replaces deliver in Action Mailer?
Use deliver_now for immediate delivery or deliver_later for asynchronous delivery.

How can I open a console on an exception page?
The Web Console gem is included by default and automatically appears on error pages.

Is render nothing: true still supported?
No, render nothing: true no longer adds a space; use head :ok instead.

Can I still use before_filter in Rails 4.2?
before_filter works but is deprecated; replace it with before_action.

Releases In Branch 4.2

VersionRelease date
4.2.11.315 May 2020
(6 years ago)
4.2.11.215 May 2020
(6 years ago)
4.2.11.113 Mar 2019
(7 years ago)
4.2.1127 Nov 2018
(7 years ago)
4.2.1027 Sep 2017
(8 years ago)
4.2.10.rc120 Sep 2017
(8 years ago)
4.2.926 Jun 2017
(8 years ago)
4.2.9.rc219 Jun 2017
(8 years ago)
4.2.9.rc113 Jun 2017
(8 years ago)
4.2.821 Feb 2017
(9 years ago)
4.2.8.rc109 Feb 2017
(9 years ago)
4.2.7.110 Aug 2016
(9 years ago)
4.2.712 Jul 2016
(9 years ago)
4.2.7.rc130 Jun 2016
(9 years ago)
4.2.607 Mar 2016
(10 years ago)
4.2.6.rc101 Mar 2016
(10 years ago)
4.2.5.229 Feb 2016
(10 years ago)
4.2.5.125 Jan 2016
(10 years ago)
4.2.512 Nov 2015
(10 years ago)
4.2.5.rc205 Nov 2015
(10 years ago)
4.2.5.rc130 Oct 2015
(10 years ago)
4.2.424 Aug 2015
(10 years ago)
4.2.4.rc114 Aug 2015
(10 years ago)
4.2.325 Jun 2015
(10 years ago)
4.2.3.rc122 Jun 2015
(10 years ago)
4.2.216 Jun 2015
(10 years ago)
4.2.119 Mar 2015
(11 years ago)
4.2.1.rc412 Mar 2015
(11 years ago)
4.2.1.rc302 Mar 2015
(11 years ago)
4.2.1.rc225 Feb 2015
(11 years ago)
4.2.1.rc120 Feb 2015
(11 years ago)
4.2.019 Dec 2014
(11 years ago)
4.2.0.rc312 Dec 2014
(11 years ago)
4.2.0.rc205 Dec 2014
(11 years ago)
4.2.0.rc128 Nov 2014
(11 years ago)
4.2.0.beta430 Oct 2014
(11 years ago)
4.2.0.beta329 Oct 2014
(11 years ago)
4.2.0.beta226 Sep 2014
(11 years ago)
4.2.0.beta119 Aug 2014
(11 years ago)