Daniel Waite wrote:
Clarification: I'm asking how YOU use them, not how TO use them.
I ask because after reading a post over at Pivotal Blabs (a very good blog, btw), it appears the Observer isn't quite meant to do what I thought it was. Example:
def before_validation(user) user.errors.add_to_base("Can't delete.") if user.admin? end
I would expect the above to halt the saving of the object because it now fails validation. But it doesn't. The record gets saved anyway.
Then I tried...
def before_validation(user) user.admin? end
Perhaps returning false would halt the process. Not so. In fact, the only way to stop a save inside an observer is to raise an exception:
I ran into exactly the same problem when I first began experimenting with observers: