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.

Adds an :on option to ActiveRecord observers

#1639

I needed to use an observer to observe multiple models, but only wanted to observe certain sets of changes on each one. There was also a bug where calling observe twice in an ActiveRecord Observer would clear out any previous list of observed classes. This patch adds both the :on option and refactors the workings of the observe method to not clear out models from previous declarations

Reported by Gabriel Gironda · December 26th, 2008 @ 09:58 PM

State: open
Milestone: 3.0.6
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Bryan Liles
    Bryan Liles

    The would read much better if you could do:

    observe :comment, :photo, :after => :create

    -or-

    observe :comment, :photo, :on => [:create, :update]

    December 27th, 2008 @ 01:12 AM

  2. Gabriel Gironda
    Gabriel Gironda

    Thanks for the comments, Bryan!

    The former, I agree with. When I get a moment I'll add that functionality to the patch.

    The latter would be a problem because there's cases where you might want before_update rather than after_update. Defaulting it to use after_ by convention would cause problems in the case where a custom callback is being used - notify(:before_some_domain_specific_event) in your models, for example.

    December 27th, 2008 @ 01:24 AM

  3. Gabriel Gironda
    Gabriel Gironda

    Here's a new patch that adds the :after => :create kind of syntax.

    January 27th, 2009 @ 10:45 PM

  4. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from patch to bugmash, patch

    August 4th, 2009 @ 06:14 PM

  5. Dan Pickett
    Dan Pickett

    +1 this is nice syntax

    having trouble applying the patch - will try to apply to master and modify as necessary

    August 8th, 2009 @ 10:44 PM

  6. Rizwan Reza
    Rizwan Reza
    • Milestone cleared.
    • Tag changed from bugmash, patch to activerecord, observers, patch
    • State changed from new to open
    • Assigned user set to Pratik

    January 20th, 2010 @ 11:11 AM

  7. Jeremy Kemper
    Jeremy Kemper
    • Milestone cleared.
    • Importance changed from to

    August 30th, 2010 @ 04:10 AM

  8. Jeremy Kemper
  9. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.

    Automatic cleanup of spam.

    November 8th, 2010 @ 08:48 AM

  10. Santiago Pastorino
  11. Santiago Pastorino
  12. Santiago Pastorino
    Santiago Pastorino
    • Milestone changed from 3.0.5 to 3.0.6

    February 27th, 2011 @ 03:15 AM