Tomar de la élite lo que pertenece a todos

Rails :after_save Callback Runs Before the Actual Database Record Is Created. So Use :after_commit Instead

| Comments

I ran into a gotcha yersterday when using the :after_save Rails callback, i hadn’t realized that the :after_save hook gets called before the SQL transaction is commited to the database. I was trying to tell asterisk to reload a queue from the database in the after_save hook using an AMI command but asterisk was not ‘seeing’ the record in the database at the time the reload command was being issued, then i realized that what i needed is called :after_commit

:after_commit is Rails 3 only but it can be used in Rails 2.x apps using the after commit gem

Happy Hacking