Silent Validation Failures

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