Rails: Exception in after_create stopping save

后端 未结 1 2047
难免孤独
难免孤独 2020-12-15 05:54

Simple question. I have a ActiveRecord model that I want to perform post processing on AFTER the record is saved. So in the model I have a queue_for_processing method that s

相关标签:
1条回答
  • 2020-12-15 06:16

    Yes, the callbacks are all wrapped up in a transaction.

    Basically, the following will cause a rollback:

    • return false from before_save or similar callbacks
    • exception in before_save or similar callbacks
    • exception in after_save or similar callbacks (after_create)

    The following do NOT cause a rollback:

    • return false from after_save or similar callbacks
    • exception in after_commit

    If you don't want an exception to cause a rollback, use after_commit

    • Reference: http://webonrails.com/2012/08/28/activerecord-after_commit-hook/
    • Additional reference: http://guides.rubyonrails.org/v3.1.3/active_record_validations_callbacks.html#transaction-callbacks
    0 讨论(0)
提交回复
热议问题