Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my Rails callback being called twice?

I have an after_commit on: :create callback in my model, and it is being called twice. There are six methods in this callback, some of which are inserting into my database. I am afraid things are going to slow down AND my database is going to grow too quickly.

What's odd is that my before_create after_create callbacks are only executing once. What could be causing this?

like image 764
Bholzer Avatar asked Aug 04 '12 02:08

Bholzer


1 Answers

Short answer: use after_save instead of after_commit

Long answer: How to organize complex callbacks in Rails?

like image 170
house9 Avatar answered Oct 24 '22 03:10

house9