Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

before and after write callbacks

#5000

I sometimes need to call the same callback after creating, saving and destroying a model.

Since it is easy to add a complete set of callbacks (before/around/after), I've added the before callback too.

This patch for ActiveRecord adds 2 callbacks : before_write and after_write.

For Rails 3.0, the after_write is called within the database transaction and have a chance to perform database modifications before the final commit, like after_save.

Both patches comes with documentation and unit tests.

Reported by Fabien Jakimowicz · June 29th, 2010 @ 03:02 AM

State: wontfix
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Fabien Jakimowicz
  2. Santiago Pastorino
    Santiago Pastorino
    • Milestone cleared.
    • Assigned user set to José Valim
    • Importance changed from to Low

    July 1st, 2010 @ 10:29 PM

  3. José Valim
    José Valim
    • State changed from new to wontfix

    Thanks for the patch Fabien, but there are not a lot of use cases that requires you to use before_write and after_write. That said, in the few cases you need it, using after_save :some_method and after_destroy :some_method works just fine. This way, we can keep the callback stack simpler. :) Thanks!

    July 2nd, 2010 @ 06:47 AM

  4. Jeremy Kemper