From 489e531334bc448c88f9b5a74f1bbbcaeb3f067b Mon Sep 17 00:00:00 2001 From: Nick Pellant Date: Mon, 7 Jul 2014 12:02:26 +0100 Subject: [PATCH 1/2] Add callbacks documentation for upgrading to 4.1. It is now expected in 4.1 to use an explicit block rather than implicit when setting callbacks through ActiveSupport::Callbacks. This commit highlights this new expectation as part of the upgrading documentation. --- guides/source/upgrading_ruby_on_rails.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 9c67391e8f35b..03be99e8f0607 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -432,6 +432,20 @@ symbol access is no longer supported. This is also the case for `store_accessors` based on top of `json` or `hstore` columns. Make sure to use string keys consistently. +### Explicit block use for `ActiveSupport::Callbacks` + +Rails 4.1 now expects an explicit block to be passed when calling +`ActiveSupport::Callbacks.set_callback`. This change stems from +`ActiveSupport::Callbacks` being largely rewritten for the 4.1 release. + +```ruby +# Rails 4.1 +set_callback :save, :around, ->(r, block) { stuff; result = block.call; stuff } + +# Rails 4.0 +set_callback :save, :around, ->(r, &block) { stuff; result = block.call; stuff } +``` + Upgrading from Rails 3.2 to Rails 4.0 ------------------------------------- From 9c3cb751f0ebf06d3ee15ae9c6279e49af9ee0e6 Mon Sep 17 00:00:00 2001 From: Nick Pellant Date: Mon, 7 Jul 2014 13:24:26 +0100 Subject: [PATCH 2/2] [ci skip] Improve callback code example for 4.1 upgrade docs. The previous code example for the new explicit block requirement when setting callbacks was a little confusing. This commit makes the example more obvious. --- guides/source/upgrading_ruby_on_rails.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 03be99e8f0607..1e752b449d334 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -439,11 +439,11 @@ Rails 4.1 now expects an explicit block to be passed when calling `ActiveSupport::Callbacks` being largely rewritten for the 4.1 release. ```ruby -# Rails 4.1 -set_callback :save, :around, ->(r, block) { stuff; result = block.call; stuff } - -# Rails 4.0 +# Previously in Rails 4.0 set_callback :save, :around, ->(r, &block) { stuff; result = block.call; stuff } + +# Now in Rails 4.1 +set_callback :save, :around, ->(r, block) { stuff; result = block.call; stuff } ``` Upgrading from Rails 3.2 to Rails 4.0