Ruby on rails 条件回调作用域

Ruby on rails 条件回调作用域,ruby-on-rails,callback,conditional,Ruby On Rails,Callback,Conditional,我的模型中有一些条件回调 before_create :save_tempfile, :if => :has_stream_content? after_create :add_track, :if => :has_stream_content? before_update :add_track, :if => :has_stream_content? 是否有一种rails方法来组织条件回调作用域?Smth是这样的: before_create :save_tempfile;

我的模型中有一些条件回调

before_create :save_tempfile, :if => :has_stream_content?
after_create :add_track, :if => :has_stream_content?
before_update :add_track, :if => :has_stream_content?
是否有一种rails方法来组织条件回调作用域?Smth是这样的:

before_create :save_tempfile; after_create, before_update :add_track, :if => :has_stream_content?
不,没有


顺便说一句,你的代码在我看来还不错。比没有新行的版本可读性好得多。

我知道,你不能拥有你想要的东西。使用
proc
可以为回调设置多个条件,但不能为多个回调设置单个条件。当前的代码是实现这一点的唯一方法。为了更好的理解和更清晰的图片,请参考此

:Active Record提供此对象生命周期的挂钩,以便您可以控制应用程序及其数据