# Unexpected behavior of before\_validation

**URL:** <https://www.ruby-forum.com/t/unexpected-behavior-of-before-validation/91196>\
**Category:** Rails\
**Created:** [April 5, 2007, 3:21pm UTC](https://www.ruby-forum.com/t/unexpected-behavior-of-before-validation/91196 "2007-04-05T15:21:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 5, 2007, 3:21pm UTC](https://www.ruby-forum.com/t/unexpected-behavior-of-before-validation/91196/1 "2007-04-05T15:21:43Z")

</div>

Today I found these comments in active record’s callbacks.rb file:

# 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 Base#save! is called it will raise a RecordNotSave error.

# Nothing will be appended to the errors object.

This caused me a lot of frustration earlier when I was trying to get a  
model with the following code to save:

before\_validation :ensure\_boolean\_value\_for\_finalized

private  
def ensure\_boolean\_value\_for\_finalized  
self.finalized = false unless self.finalized  
end

I’m wondering why before\_validation will abort the process of saving.  
My conception of before\_validation was that its purpose was only to  
prepare the model object for validation, and that its purpose was  
_not_ to do pre-validation validation.

It’s not a huge deal - I’m just wondering what the logic behind  
before\_validation’s behavior is.

Daniel  
[http://www.hallwaytesting.com](http://www.hallwaytesting.com)
