Reputation: 964
I have the line below in one of my models:
skip_callback :create, :after, :creation_email, if: -> { self.template_email }
template_email
is a method in the model, that based on associated data will return true or false. The method is returning true
, but the callback is not being skipped.
Upvotes: 2
Views: 330
Reputation: 3798
In Rails 4 :
after_create :creation_email, if: :template_email #execute if true
after_create :creation_email, unless: :template_email #skip if true
Something this way it can be done. Here creation_email is invoked when template_email method returns true otherwise skips invoking.
Upvotes: 2