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?
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?
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] Peak Obsession
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs