Rails 5 does not halt callback chain when false is returned

Rails 升级到 5 以后,突然发现before_save的时候,return false 不生效了,Google一下,第一篇就是解决方案。

Rails 5 does not halt callback chain when false is returned
http://blog.bigbinary.com/2016/02/13/rails-5-does-not-halt-callback-chain-when-false-is-returned.html

解决方案一,使用 throw(:abort) 来跳出代码
解决方案二,修改配置,对应配置在initializers/new_framework_defaults.rb中
ActiveSupport.halt_callback_chains_on_return_false = false
值改为true

你可能感兴趣的:(Rails 5 does not halt callback chain when false is returned)