Colin Law wrote in post #1071428:
> On 6 August 2012 14:30, masta Blasta <[email protected]> wrote:
>> How do these before validation callbacks work? Are they just simple
>> function callbacks, or can you return false or errors.add in them to
>> halt the rest of the record.save code?
>
> Have a look at the Rails Guide on ActiveRecord Validations and
> Callbacks.  That may answer your questions.
>
> Colin

Thanks for the pointer.

Here's the quick answer for future users, from RoR api:


"If the returning value of a before_validation callback can be evaluated 
to false, the process will be aborted and Base#save will return false. 
If ActiveRecord::Validations#save! is called it will raise a 
ActiveRecord::RecordInvalid exception. Nothing will be appended to the 
errors object.

...

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."

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to