Ruby on rails 如果条件不起作用,Rails跳过\u回调

Ruby on rails 如果条件不起作用,Rails跳过\u回调,ruby-on-rails,callback,Ruby On Rails,Callback,在我的一个模型中,我有以下行: skip_callback :create, :after, :creation_email, if: -> { self.template_email } template\u email是模型中的一种方法,它基于相关数据将返回true或false。该方法返回true,但不会跳过回调。在Rails 4中: after_create :creation_email, if: :template_email #execute if true after_cr

在我的一个模型中,我有以下行:

skip_callback :create, :after, :creation_email, if: -> { self.template_email }
template\u email
是模型中的一种方法,它基于相关数据将返回true或false。该方法返回
true
,但不会跳过回调。

在Rails 4中:

after_create :creation_email, if: :template_email #execute if true
after_create :creation_email, unless: :template_email #skip if true
通过这种方式可以做到。
此处,当模板\u email方法返回true时,将调用创建\u email,否则将跳过调用。

否,仅当它为true时,我才想跳过。如果上面的代码片段为真,则不会跳过它。