Elad O
2011-Aug-30 04:23 UTC
Rails 3: How to identify after_commit action? (create/update/destroy)
I have an observer and I register an `after_commit` callback. How can I tell weather it was fired after create or update? I can tell an item was destroyed by asking `item.destroyed?`. I was going to solve it by adding `after_create`/`after_update` and do something like `@action = :create` inside and check the `@action` at `after_commit`, but it seems that the observer instance is a singleton and I might just override a value before it gets to the `after_commit`. So I solved it in an uglier way, storing the action in a map based on the item.id on after_create/update and checking its value on after_commit. Really ugly. Is there any other way? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.