It seems possible that the on: attribute is not referenced in the 
after_rollback callback. Is it listed in the documentation?

You could probably get the same result by adding a test inside your method:

after_rollback {
  return if persisted?
  // whatever else here
}

This will only ever proceed beyond that checkpoint if the record was in the 
process of being created, since on an update or delete, the record would be 
persisted (have an ID).

Walter

> On May 20, 2019, at 8:58 AM, Cevad Tokatlı <cevadtokatl...@gmail.com> wrote:
> 
> I have a product table and I try to run after_commit and after_rollback on 
> create.
> 
> 
> 
> controller:
> 
>   product = Product.
> new form_params
>   
> if product.
> save
>     
> # code
> 
>   
> else
> 
>     
> # code
> 
>   
> end
> 
> 
> model:
> 
>   after_commit(on: :create) {
> 
>     
> # code
> 
>   
> }
> 
> 
>   after_rollback
> (on: :create) {
> 
>     
> # code
> 
>   
> }
> 
> 
> after_commit works well but after_rollback wont work with on: :create param. 
> When I remove the on: :create param, it triggers too but I need 
> after_rollback to trigger just on create.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-talk+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rubyonrails-talk/c0ad4f7b-d303-4fb8-8dc2-f72ea3517573%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/D5D2DF05-FC53-4915-A068-5C539ED40FF1%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to