Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Warn about using `return` inside inline callback blocks [ci skip]

Closes #12981
  • Loading branch information...
commit 68abbac2fc6ef8808e1788be9c4f41581674d17f 1 parent 11c0ef5
@chancancode chancancode authored
Showing with 33 additions and 0 deletions.
  1. +33 −0 guides/source/
33 guides/source/
@@ -93,6 +93,39 @@ If you application depends on one of these features, you can get them back by
adding the [`activesupport-json_encoder`](
gem to your Gemfile.
+### Usage of `return` within inline callback blocks
+Previously, Rails allowed you to `return` from an inline callback block:
+class ReadOnlyModel < ActiveRecord::Base
+ before_save { return false }
+This behaviour was never intentionally supported. Due to a change in the internals
+of `ActiveSupport::Callbacks`, this is no longer allowed in Rails 4.1. Using a
+`return` statement in an inline callback block will cause a `LocalJumpError` to
+be raised when the callback is executed. If you need to use `return` statements
+in your callbacks, it is recommended that you explicitly define them as methods
+and pass the method name as a symbol instead:
+class ReadOnlyModel < ActiveRecord::Base
+ before_save :before_save_callback
+ private
+ def before_save_callback
+ return false
+ end
+This change applies to most places in Rails where callbacks are used, including
+Active Record and Active Model callbacks, as well as "filters" in Action
+Controller (e.g. `before_action`). See [this pull request](
+for more details.
### Methods defined in Active Record fixtures
Rails 4.1 evaluates each fixture's ERB in a separate context, so helper methods
Please sign in to comment.
Something went wrong with that request. Please try again.