# Silent Validation Failures

**URL:** <https://www.ruby-forum.com/t/silent-validation-failures/124330>\
**Category:** Rails\
**Created:** [December 27, 2007, 6:40pm UTC](https://www.ruby-forum.com/t/silent-validation-failures/124330 "2007-12-27T18:40:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tatyree](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/f14d63/32.png) [@tatyree](https://www.ruby-forum.com/u/tatyree)\
**Post date:** [December 27, 2007, 6:40pm UTC](https://www.ruby-forum.com/t/silent-validation-failures/124330/1 "2007-12-27T18:40:51Z")

</div>

Hello,

I’m having trouble with after\_validation\_on\_create causing my  
validations to fail silently. I’ve got a restful\_authentication based  
user model that requires a number of things from the user: email, dob,  
gender, etc. When a user is created, all of these are validated in  
various ways (presence, inclusion\_of, etc.). Afterwards, I call three  
protected methods using after\_validation\_on\_create. These make the  
user an alias, a password and a profile. The problem I’m having is  
that rely on data the user enters (like gender) to generate their  
information correctly. So long as I do not call  
after\_validation\_on\_create, the validations all work fine and the  
controller passes the errors back to the view. However, the moment I  
uncomment the after\_validation\_on\_create line in my model all the  
validations stop working. I only know they haven’t worked because the  
private methods throw NoMethodErrors when the user doesn’t enter  
something.

Here’s an example:

validates\_acceptance\_of :terms\_of\_service, :on  
=\> :create, :allow\_nil =\> false  
validates\_length\_of :email, :within =\> 6…100  
validates\_uniqueness\_of :user\_alias, :email, :case\_sensitive =\>  
false  
validates\_inclusion\_of :gender, :in =\> %w( m f ), :message =\> ‘: So  
what are you then?’

after\_validation\_on\_create :make\_new\_alias

…

protected  
def make\_new\_alias  
self.user\_alias = “#{get\_random\_word(:gender =\>  
self.gender ).word.downcase}.to\_s}”  
end

Get random word is just a find off of a table of exactly that.

Any one have any ideas why this might be happening? Is there anything  
I can do about it?

Best,  
TA
