通过 false 终止回调执行不起作用,google 一番未果,怒跟源码,发现如下:
activesupport-5.0.0.1/lib/active_support/callbacks.rb
def deprecated_false_terminator # :nodoc:
Proc.new do |target, result_lambda|
terminate = true
catch(:abort) do
result = result_lambda.call if result_lambda.is_a?(Proc)
if Callbacks.halt_and_display_warning_on_return_false && result == false
display_deprecation_warning_for_false_terminator
else
terminate = false
end
end
terminate
end
end
需要用 throw(:abort) 终止回调执行,官方文档还未更新
http://guides.rubyonrails.org/active_record_callbacks.html#halting-execution
国外一哥们的总结: