* Leave two blank lines between sections/packages for readibility. * Always indent bullet points with four spaces. This allows multi-paragraph points to align properly (see #16103), and it is the same as the format we already use in CHANGELOGs. Doing this consistently sets an easy precedent for future contributors to follow. * Always put the PR/commit link on its own line in the source. If the bullet point spans multiple paragraphs, put it on its own paragraph at the end. [Godfrey Chan & Juanito Fatas]
15 KiB
Ruby on Rails 4.2 Release Notes
Highlights in Rails 4.2:
These release notes cover only the major changes. To know about various bug fixes and changes, please refer to the change logs or check out the list of commits in the main Rails repository on GitHub.
Upgrading to Rails 4.2
If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 4.1 in case you haven't and make sure your application still runs as expected before attempting an update to Rails 4.2. A list of things to watch out for when upgrading is available in the Upgrading Ruby on Rails guide.
Major Features
Foreign key support
The migration DSL now supports adding and removing foreign keys. They are dumped
to schema.rb
as well. At this time, only the mysql
, mysql2
and postgresql
adapters support foreign keys.
# add a foreign key to `articles.author_id` referencing `authors.id`
add_foreign_key :articles, :authors
# add a foreign key to `articles.author_id` referencing `users.lng_id`
add_foreign_key :articles, :users, column: :author_id, primary_key: "lng_id"
# remove the foreign key on `accounts.branch_id`
remove_foreign_key :accounts, :branches
# remove the foreign key on `accounts.owner_id`
remove_foreign_key :accounts, column: :owner_id
See the API documentation on add_foreign_key and remove_foreign_key for a full description.
Railties
Please refer to the Changelog for detailed changes.
Removals
- The
rails application
command has been removed without replacement. (Pull Request)
Deprecations
- Deprecated
Rails::Rack::LogTailer
without replacement. (Commit)
Notable changes
-
Introduced
--skip-gems
option in the app generator to skip gems such asturbolinks
andcoffee-rails
that does not have their own specific flags. (Commit) -
Introduced
bin/setup
script to bootstrap an application. (Pull Request) -
Changed default value for
config.assets.digest
totrue
in development. (Pull Request) -
Introduced an API to register new extensions for
rake notes
. (Pull Request) -
Introduced
Rails.gem_version
as a convenience method to returnGem::Version.new(Rails.version)
. (Pull Request)
Action Pack
Please refer to the Changelog for detailed changes.
Deprecations
-
Deprecated support for setting the
:to
option of a router to a symbol or a string that does not contain a#
character:get '/posts', to: MyRackApp => (No change necessary) get '/posts', to: 'post#index' => (No change necessary) get '/posts', to: 'posts' => get '/posts', controller: :posts get '/posts', to: :index => get '/posts', action: :index
(Commit)
Notable changes
-
render nothing: true
or rendering anil
body no longer add a single space padding to the response body. (Pull Request) -
Introduced the
always_permitted_parameters
option to configure which parameters are permitted globally. The default value of this configuration is['controller', 'action']
. (Pull Request) -
The
*_filter
family methods has been removed from the documentation. Their usage are discouraged in favor of the*_action
family methods:after_filter => after_action append_after_filter => append_after_action append_around_filter => append_around_action append_before_filter => append_before_action around_filter => around_action before_filter => before_action prepend_after_filter => prepend_after_action prepend_around_filter => prepend_around_action prepend_before_filter => prepend_before_action skip_after_filter => skip_after_action skip_around_filter => skip_around_action skip_before_filter => skip_before_action skip_filter => skip_action_callback
If your application is depending on these methods, you should use the replacement
*_action
methods instead. These methods will be deprecated in the future and eventually removed from Rails. -
Added HTTP method
MKCALENDAR
from RFC-4791 (Pull Request) -
*_fragment.action_controller
notifications now include the controller and action name in the payload. (Pull Request) -
Segments that are passed into URL helpers are now automatically escaped. (Commit)
-
Improved Routing Error page with fuzzy matching for route search. (Pull Request)
-
Added option to disable logging of CSRF failures. (Pull Request)
Action View
Please refer to the Changelog for detailed changes.
Deprecations
-
Deprecated
AbstractController::Base.parent_prefixes
. OverrideAbstractController::Base.local_prefixes
when you want to change where to find views. (Pull Request) -
Deprecated
ActionView::Digestor#digest(name, format, finder, options = {})
, arguments should be passed as a hash instead. (Pull Request)
Notable changes
- The form helpers no longer generate a
<div>
element with inline CSS around the hidden fields. (Pull Request)
Action Mailer
Please refer to the Changelog for detailed changes.
Notable changes
- Added the
show_previews
configuration option for enabling mailer previews outside of the development environment. (Pull Request)
Active Record
Please refer to the Changelog for detailed changes.
Removals
-
Removed
cache_attributes
and friends. All attributes are cached. (Pull Request) -
Removed deprecated method
ActiveRecord::Base.quoted_locking_column
. (Pull Request) -
Removed deprecated
ActiveRecord::Migrator.proper_table_name
. Use theproper_table_name
instance method onActiveRecord::Migration
instead. (Pull Request) -
Removed unused
:timestamp
type. Transparently alias it to:datetime
in all cases. Fixes inconsistencies when column types are sent outside ofActiveRecord
, such as for XML Serialization. (Pull Request)
Deprecations
-
Deprecated broken support for automatic detection of counter caches on
has_many :through
associations. You should instead manually specify the counter cache on thehas_many
andbelongs_to
associations for the through records. (Pull Request) -
Deprecated
serialized_attributes
without replacement. (Pull Request) -
Deprecated returning
nil
fromcolumn_for_attribute
when no column exists. It will return a null object in Rails 5.0 (Pull Request) -
Deprecated using
.joins
,.preload
and.eager_load
with associations that depends on the instance state (i.e. those defined with a scope that takes an argument) without replacement. (Commit) -
Deprecated passing Active Record objects to
.find
or.exists?
. Call#id
on the objects first. (Commit 1, 2) -
Deprecated half-baked support for PostgreSQL range values with excluding beginnings. We currently map PostgreSQL ranges to Ruby ranges. This conversion is not fully possible because the Ruby range does not support excluded beginnings.
The current solution of incrementing the beginning is not correct and is now deprecated. For subtypes where we don't know how to increment (e.g.
#succ
is not defined) it will raise anArgumentError
for ranges with excluding beginnings.(Commit)
Notable changes
-
Added a
:required
option to singular associations, which defines a presence validation on the association. (Pull Request) -
Introduced
ActiveRecord::Base#validate!
that raisesRecordInvalid
if the record is invalid. (Pull Request) -
ActiveRecord::Base#reload
now behaves the same asm = Model.find(m.id)
, meaning that it no longer retains the extra attributes from customselect
s. (Pull Request) -
Introduced the
bin/rake db:purge
task to empty the database for the current environment. (Commit) -
ActiveRecord::Dirty
now detects in-place changes to mutable values. Serialized attributes on ActiveRecord models will no longer save when unchanged. This also works with other types such as string columns and json columns on PostgreSQL. (Pull Requests 1, 2, 3) -
Added support for
#pretty_print
inActiveRecord::Base
objects. (Pull Request) -
PostgreSQL and SQLite adapters no longer add a default limit of 255 characters on string columns. (Pull Request)
-
sqlite3:///some/path
now resolves to the absolute system path/some/path
. For relative paths, usesqlite3:some/path
instead. (Previously,sqlite3:///some/path
resolved to the relative pathsome/path
. This behaviour was deprecated on Rails 4.1.) (Pull Request) -
Introduced
#validate
as an alias for#valid?
. (Pull Request) -
#touch
now accepts multiple attributes to be touched at once. (Pull Request) -
Added support for fractional seconds for MySQL 5.6 and above. (Pull Request 1, 2)
-
Added support for the
citext
column type in PostgreSQL adapter. (Pull Request) -
Added support for user-created range types in PostgreSQL adapter. (Commit)
Active Model
Please refer to the Changelog for detailed changes.
Removals
- Removed deprecated
Validator#setup
without replacement. (Pull Request)
Notable changes
-
Introduced
undo_changes
method inActiveModel::Dirty
to restore the changed (dirty) attributes to their previous values. (Pull Request) -
has_secure_password
now verifies that the given password is less than 72 characters if validations are enabled. (Pull Request) -
Introduced
#validate
as an alias for#valid?
. (Pull Request)
Active Support
Please refer to the Changelog for detailed changes.
Removals
-
Removed deprecated
Numeric#ago
,Numeric#until
,Numeric#since
,Numeric#from_now
. (Commit) -
Removed deprecated string based terminators for
ActiveSupport::Callbacks
. (Pull Request)
Deprecations
-
Deprecated
Class#superclass_delegating_accessor
, useClass#class_attribute
instead. (Pull Request) -
Deprecated
ActiveSupport::SafeBuffer#prepend!
asActiveSupport::SafeBuffer#prepend
now performs the same function. (Pull Request)
Notable changes
-
Added
Hash#transform_values
andHash#transform_values!
to simplify a common pattern where the values of a hash must change, but the keys are left the same. (Pull Request) -
The
humanize
inflector helper now strips any leading underscores. (Commit) -
Introduce
Concern#class_methods
as an alternative tomodule ClassMethods
, as well asKernel#concern
to avoid themodule Foo; extend ActiveSupport::Concern; end
boilerplate. (Commit)
Credits
See the full list of contributors to Rails for the many people who spent many hours making Rails the stable and robust framework it is today. Kudos to all of them.