With Ruby on Rails 5.1.0 RC1 out now, its official release is probably right around the corner. In efforts to clean up some of the code base, some methods have been deprecated. If you have been keeping your apps up to date with the latest stable releases, chances are that you have noticed these for some time coming as the via the deprecation notices in the application logs.
For easy searching purposes, I've parsed through the logs of all of the upcoming deprecations in Ruby on Rails 5.1.0. These were taken straight out of the CHANGELOGs.
Check out https://www.driftingruby.com/episodes/ruby-on-rails-5-1-0-changes-and-new-features for a screencast of some of the upcoming features in Ruby on Rails 5.1.0.
Action Pack
https://github.com/rails/rails/blob/v5.1.0.rc1/actionpack/CHANGELOG.md
Removed Deprecations
- Remove deprecated
.to_prepare
,.to_cleanup
,.prepare!
and.cleanup!
fromActionDispatch::Reloader
. - Remove deprecated
ActionDispatch::Callbacks.to_prepare
andActionDispatch::Callbacks.to_cleanup
. - Remove deprecated
ActionController::Metal.call
. - Remove deprecated
ActionController::Metal#env
. - Remove deprecated support to non-keyword arguments in
ActionDispatch::IntegrationTest#process
,#get
,#post
,#patch
,#put
,#delete
, and#head
.
- Remove deprecated
ActionDispatch::IntegrationTest#*_via_redirect
. - Remove deprecated
ActionDispatch::IntegrationTest#xml_http_request
. - Remove deprecated support for passing
:path
and route path as strings inActionDispatch::Routing::Mapper#match
. - Remove deprecated support for passing path as
nil
inActionDispatch::Routing::Mapper#match
. - Remove deprecated
cache_control
argument fromActionDispatch::Static#initialize
. - Remove deprecated support to passing strings or symbols to the middleware stack.
- Remove deprecated
host
andport
ssl options. - Remove deprecated
const_error
argument inActionDispatch::Session::SessionRestoreError#initialize
. - Remove deprecated
#original_exception
inActionDispatch::Session::SessionRestoreError
. - Remove deprecated
ActionDispatch::ParamsParser
. - Remove deprecated
original_exception
andmessage
arguments inActionDispatch::ParamsParser::ParseError#initialize
. - Remove deprecated
#original_exception
inActionDispatch::ParamsParser::ParseError
. - Remove deprecated access to mime types through constants.
- Remove deprecated support to non-keyword arguments in
ActionController::TestCase#process
,#get
,#post
,#patch
,#put
,#delete
, and#head
. - Remove deprecated
xml_http_request
andxhr
methods inActionController::TestCase
. - Remove deprecated methods in
ActionController::Parameters
. - Remove deprecated support to comparing a
ActionController::Parameters
with aHash
. - Remove deprecated support to
:text
inrender
. - Remove deprecated support to
:nothing
inrender
. - Remove deprecated support to
:back
inredirect_to
. - Remove deprecated support to passing status as option
head
. - Remove deprecated support to passing original exception to
ActionController::BadRequest
and theActionController::BadRequest#original_exception
method. - Remove deprecated methods
skip_action_callback
,skip_filter
,before_filter
,prepend_before_filter
,skip_before_filter
,append_before_filter
,around_filter
prepend_around_filter
,skip_around_filter
,append_around_filter
,after_filter
,prepend_after_filter
,skip_after_filter
andappend_after_filter
.
New Deprecations
- Deprecate
ActionDispatch::ParamsParser::ParseError
in favor ofActionDispatch::Http::Parameters::ParseError
.
ActionView
https://github.com/rails/rails/blob/v5.1.0.rc1/actionview/CHANGELOG.md
Removed Deprecations
- Removed deprecated
#original_exception
inActionView::Template::Error
.
New Deprecations
- Deprecation: The Erubis handler will be removed in Rails 5.2, for the handful of folks using it directly.
ActiveModel
https://github.com/rails/rails/blob/v5.1.0.rc1/activemodel/CHANGELOG.md
Removed Deprecations
- Remove deprecated behavior that halts callbacks when the return is false.
- Remove unused
ActiveModel::TestCase
class. - Removed deprecated
:tokenizer
in the length validator. - Removed deprecated methods in
ActiveModel::Errors
.#get
,#set
,[]=
,add_on_empty
andadd_on_blank
.
ActiveRecord
https://github.com/rails/rails/blob/v5.1.0.rc1/activerecord/CHANGELOG.md
Removed Deprecations
- Remove deprecated behavior that halts callbacks when the return is false.
- Remove deprecated tasks:
db:test:clone
,db:test:clone_schema
,db:test:clone_structure
. - Remove deprecated
#uniq
,#uniq!
, and#uniq_value
. - Remove deprecated
#insert_sql
,#update_sql
, and#delete_sql
. - Remove deprecated
#use_transactional_fixtures
configuration. - Remove deprecated
#raise_in_transactional_callbacks
configuration. - Remove deprecated
#load_schema_for
. - Remove deprecated conditions parameter from
#destroy_all
and#delete_all
. - Remove deprecated support to passing arguments to
#select
when a block is provided. - Remove deprecated support to query using commas on LIMIT.
- Remove deprecated support to passing a class as a value in a query.
- Remove deprecated
original_exception
argument inActiveRecord::StatementInvalid#initialize
andActiveRecord::StatementInvalid#original_exception
. #tables
and#table_exists?
return only tables and not views.All the deprecations on those methods were removed.- Remove deprecated
name
argument from#tables
. - Remove deprecated support to passing a column to
#quote
. - Remove deprecated force reload argument in singular and collection association readers.
- Remove deprecated
activerecord.errors.messages.restrict_dependent_destroy.one
andactiverecord.errors.messages.restrict_dependent_destroy.many
i18n scopes.
New Deprecations
- Deprecate
Migrator.schema_migrations_table_name
. - Deprecate
supports_migrations?
on connection adapters. - Deprecate using
#quoted_id
in quoting. - Deprecate passing
default
toindex_name_exists?
. - Deprecate
supports_primary_key?
on connection adapters since it's been long unused and unsupported. - Deprecate locking records with unpersisted changes.
- Deprecate
ColumnDumper#migration_keys
. - Deprecate
initialize_schema_migrations_table
andinitialize_internal_metadata_table
. - Deprecate passing a class to the
class_name
because it eagerloads more classes than necessary and potentially creates circular dependencies. - Deprecate passing
name
toindexes
. - Deprecate passing arguments and block at the same time to
ActiveRecord::QueryMethods#select
. - Deprecate
sanitize_conditions
. Usesanitize_sql
instead.
ActiveSupport
https://github.com/rails/rails/blob/v5.1.0.rc1/activesupport/CHANGELOG.md
Removed Deprecations
- Remove deprecated behavior that halts callbacks when the return is false.
- Remove deprecated class
ActiveSupport::Concurrency::Latch
. - Remove deprecated separator argument from
parameterize
. - Remove deprecated method
Numeric#to_formatted_s
. - Remove deprecated method
alias_method_chain
. - Remove deprecated constant
MissingSourceFile
. - Remove deprecated methods
Module.qualified_const_defined?
,Module.qualified_const_get
andModule.qualified_const_set
. - Remove deprecated
:prefix
option fromnumber_to_human_size
. - Remove deprecated method
ActiveSupport::HashWithIndifferentAccess.new_from_hash_copying_default
. - Remove deprecated file
active_support/core_ext/time/marshal.rb
. - Remove deprecated file
active_support/core_ext/struct.rb
. - Remove deprecated file
active_support/core_ext/module/method_transplanting.rb
. - Remove deprecated method
Module.local_constants
. - Remove deprecated file
active_support/core_ext/kernel/debugger.rb
. - Remove deprecated method
ActiveSupport::Cache::Store#namespaced_key
. - Remove deprecated method
ActiveSupport::Cache::Strategy::LocalCache::LocalStore#set_cache_value
. - Remove deprecated method
ActiveSupport::Cache::MemCacheStore#escape_key
. - Remove deprecated method
ActiveSupport::Cache::FileStore#key_file_path
. - Remove deprecated arguments in
assert_nothing_raised
.
New Deprecations
- Deprecate implicit coercion of
ActiveSupport::Duration
CurrentlyActiveSupport::Duration
implicitly converts to a seconds value when used in a calculation except for the explicit examples of addition and subtraction where the duration is the receiver, e.g: >> 2 * 1.day => 172800
This results in lots of confusion especially when using durations with dates because adding/subtracting a value from a date treats integers as a day and not a second, e.g:>> Date.today => Wed, 01 Mar 2017 >> Date.today + 2 * 1.day => Mon, 10 Apr 2490
To fix this we're implementing coerce
so that we can provide a deprecation warning with the intent of removing the implicit coercion in Rails 5.2, e.g:>> 2 * 1.day DEPRECATION WARNING: Implicit coercion of ActiveSupport::Duration to a Numeric is deprecated and will raise a TypeError in Rails 5.2. => 172800
In Rails 5.2 it will raise TypeError
, e.g:>> 2 * 1.day TypeError: ActiveSupport::Duration can't be coerced into Integer
This is the same behavior as with other types in Ruby, e.g:>> 2 * "foo" TypeError: String can't be coerced into Integer >> "foo" * 2 => "foofoo"
As part of this deprecation add *
and /
methods to AS::Duration
so that calculations that keep the duration as the receiver work correctly whether the final receiver is a Date
or Time
, e.g:>> Date.today => Wed, 01 Mar 2017 >> Date.today + 1.day * 2 => Fri, 03 Mar 2017
Fixes #27457.
- Soft-deprecated the top-level
HashWithIndifferentAccess
constant.ActiveSupport::HashWithIndifferentAccess
should be used instead.Fixes #28157. - Deprecate
ActiveSupport.halt_callback_chains_on_return_false
. - Deprecate passing string to
:if
and:unless
conditional options onset_callback
andskip_callback
.
ActiveJob
https://github.com/rails/rails/blob/v5.1.0.rc1/activejob/CHANGELOG.md
Removed Deprecations
- Removed deprecated support to passing the adapter class to
.queue_adapter
. - Removed deprecated
#original_exception
inActiveJob::DeserializationError
.
New Deprecations
- None
Railsties
https://github.com/rails/rails/blob/v5.1.0.rc1/railties/CHANGELOG.md
Removed Deprecations
- Remove deprecated
CONTROLLER
environment variable forroutes
task. - Remove deprecated tasks:
rails:update
,rails:template
,rails:template:copy
,rails:update:configs
andrails:update:bin
. - Remove deprecated file
rails/rack/debugger
. - Remove deprecated
config.serve_static_files
. - Remove deprecated
config.static_cache_control
. - Removed jquery-rails from default stack, instead rails-ujs that is shipped with Action View is included as default UJS adapter.
New Deprecations
- None