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:
class UserObserver
def before_validation(user) user.errors.add_to_base("Can't delete.") if user.admin? end
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...
class UserObserver
def before_validation(user) user.admin? end
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: