Stopping a save from the before_save


#1

What’s the better thing to do in a before_save if you don’t want the
save to continue?

raise an exception, or do an errors.add or both?

Thanks,
Chris Nolan.ca
http://kweschun.com/ - Do you have a Kweschun?


#2

On 3.1.2006, at 9.56, Chris Nolan.ca wrote:

What’s the better thing to do in a before_save if you don’t want
the save to continue?

Return false.

“If a before_* callback returns false, all the later callbacks and
the associated action are cancelled. If an after_* callback returns
false, all the later callbacks are cancelled. Callbacks are generally
run in the order they are defined, with the exception of callbacks
defined as methods on the model, which are called last.” [1]

//jarkko

[1] http://api.rubyonrails.com/classes/ActiveRecord/Callbacks.html


#3

On 3-jan-2006, at 10:32, Jarkko L. wrote:

What’s the better thing to do in a before_save if you don’t want
the save to continue?

Return false.

"If a before_* callback returns false, all the later callbacks and
the associated action are cancelled. If an after_* callback returns
false, all the later callbacks are cancelled.

Does that mean that raising an exception in a callback doesn’t cancel
later callbacks?

When returning false, how do you detect which callback return false?


Regards, Charles.