Nicholas Morgan Sun Nov 20 08:14:16 -0500 2011

Subject: $after_validation_on_create callback not working as expected???

I am having a problem with my password validation. When creating a new user, I want the model to validate the plaintext password, and then encrypt it, and then save it. What I currently have (which I fully believe should work based on what the documentation tells me) isn't working.

The current code in my User model can be found here:
NOTE: I stripped out all code that doesn't have anything to do with the password

My encrypt_password function returns a 128 character string. No matter what I do, the password field fails the following validations: $validates_format_of and $validates_size_of, because it's validating against the hashed 128 character string, not the plaintext password. It appears that the $before_create callback is happening before the validations.

Nicholas Morgan Sun Nov 20 09:37:22 -0500 2011


Turns out it was not an error whatsoever with the model. It was something I was doing in my controller.

function register()
if(isset($_POST['submit'])) {
$user = User::register($_POST);
$this->view_data['user'] = $user;

The model was being created exactly as it is supposed to. However, after I created the model, I immediately checked to see if that model was valid. Since password was being encrypted into a 128 character string, the model would no longer validate due to the password field being now encrypted.

WHEW that feels good to have figured out! o:-)