Tuesday, November 2, 2010

[Rails] User validation of password

I have a User model that validates password presence:
validates :password, :presence => true,
:confirmation => true,
:length => { :within => 6..40 },

Password is never stored in the db. Now the problem is that the user
has a:
belongs_to :owner, :polymorphic => :true

This means it contains a key to the owner. When setting the owner, the
user.save will be called and the password validation will fail as
password is not present at that time. I also have several other data
like user.personal_message that I was updating through save, :validate
=> false.

How can I still keep my password validations and be able to internally
call save and run all but those validations(I.E I only want the
password validations to run when user edits the user or creates a new
user). Its really important to validate when editing( on update)

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate