diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-01-03 17:22:20 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-01-03 17:22:20 -0300 |
commit | 4591b0fc041454f4ba4a83629b9bbca2a851969c (patch) | |
tree | 21b9019ee5d471205ccde051977d3c92b0a4f800 /guides | |
parent | 900758145d65438190a69f0fd227f62e01fa7bd2 (diff) | |
parent | 9c65c539e2caa4590aded1975aead008f8135da4 (diff) | |
download | rails-4591b0fc041454f4ba4a83629b9bbca2a851969c.tar.gz rails-4591b0fc041454f4ba4a83629b9bbca2a851969c.tar.bz2 rails-4591b0fc041454f4ba4a83629b9bbca2a851969c.zip |
Merge pull request #17227 from claudiob/explicitly-abort-callbacks
Introduce explicit way of halting callback chains by throwing :abort. Deprecate current implicit behavior of halting callback chains by returning `false` in apps ported to Rails 5.0. Completely remove that behavior in brand new Rails 5.0 apps.
Conflicts:
railties/CHANGELOG.md
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/configuring.md | 2 | ||||
-rw-r--r-- | guides/source/upgrading_ruby_on_rails.md | 22 |
2 files changed, 24 insertions, 0 deletions
diff --git a/guides/source/configuring.md b/guides/source/configuring.md index 0a375d7cb8..5baab8a4b5 100644 --- a/guides/source/configuring.md +++ b/guides/source/configuring.md @@ -507,6 +507,8 @@ There are a few configuration options available in Active Support: * `config.active_support.time_precision` sets the precision of JSON encoded time values. Defaults to `3`. +* `config.active_support.halt_callback_chains_on_return_false` specifies whether ActiveRecord, ActiveModel and ActiveModel::Validations callback chains can be halted by returning `false` in a 'before' callback. Defaults to `true`. + * `ActiveSupport::Logger.silencer` is set to `false` to disable the ability to silence logging in a block. The default is `true`. * `ActiveSupport::Cache::Store.logger` specifies the logger to use within cache store operations. diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 0b9f59bb46..c0c94475e0 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -53,6 +53,28 @@ Don't forget to review the difference, to see if there were any unexpected chang Upgrading from Rails 4.2 to Rails 5.0 ------------------------------------- +### Halting callback chains by returning `false` + +In Rails 4.2, when a 'before' callback returns `false` in ActiveRecord, +ActiveModel and ActiveModel::Validations, then the entire callback chain +is halted. In other words, successive 'before' callbacks are not executed, +and neither is the action wrapped in callbacks. + +In Rails 5.0, returning `false` in a callback will not have this side effect +of halting the callback chain. Instead, callback chains must be explicitly +halted by calling `throw(:abort)`. + +When you upgrade from Rails 4.2 to Rails 5.0, returning `false` in a callback +will still halt the callback chain, but you will receive a deprecation warning +about this upcoming change. + +When you are ready, you can opt into the new behavior and remove the deprecation +warning by adding the following configuration to your `config/application.rb`: + + config.active_support.halt_callback_chains_on_return_false = false + +See [#17227](https://github.com/rails/rails/pull/17227) for more details. + Upgrading from Rails 4.1 to Rails 4.2 ------------------------------------- |