Help with validations

Hi,

I am trying to use the new rails 3 validations and running into some
issues.

for my password I have,

validates :password, :presence => {:on => :create}, :length => {
:minimum => 5, :maximum => 16 }, :confirmation => true

the presence and length are creating problem.

I only want to be able to check for the password at create time to
confirm if it is present.

at update time if someone enters the password it should still match the
size limit but it they do not enter the password then it should not be
looked at.

in my controller i have already added:

params[:user].delete(:password) if params[:user][:password].blank?
params[:user].delete(:password_confirmation) if
params[:user][:password].blank? and
params[:user][:password_confirmation].blank?

to take care of any issue coming from that side.

any help or suggestion will be greatly appriciated.

On Wed, May 11, 2011 at 2:36 AM, Quee WM [email protected] wrote:

the presence and length are creating problem.

I only want to be able to check for the password at create time to
confirm if it is present.

at update time if someone enters the password it should still match the
size limit but it they do not enter the password then it should not be
looked at.

My sense is that what is tripping things up is that on update and nil
password, it is not checking precence but is still checking length and
confirmation. It may not be the best way but I tend to use an :if =>
:method_name, and then in that method check for new_record, etc.

Thanks for the reply David.

I am not that good is rails so will need a bit more help.

Is it possible for you to provide me with an example on how to use this
if condition.

I searched on the net and it did not become as clear to me.

Regards,

Q

You may try this:
validates :password, :if => Model.create{:presence => true}, :length
=> {
:minimum => 5, :maximum => 16 }, :confirmation => true

On Wed, May 11, 2011 at 1:06 PM, Quee WM [email protected] wrote:

the presence and length are creating problem.
params[:user].delete(:password) if params[:user][:password].blank?


You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

Please consider the environment before printing this email.

Regards,
Surya

Hey, it would help to include your full functions that you are talking
about, as well as the error messages you are experiencing (if so).