Prevent fields from being validated

Hi all,

when my user edit its account - he can leave the password field blank to
leave the used password untouched.

but he cant leave it blank - because the validation process in my user
modell validates the password field all the way and throws of course an
error if the user leave it blank.

I also have a password_confirmation field that only needs to validat if
a password is given.

validates_confirmation_of :password
validates_presence_of :password

I read something from
attr_accessor :password

but I dont understand the function of this attribute

How can I go around this?

I am happy for any help
thanks
Andreas

Andreas S. wrote:

validates_confirmation_of :password
validates_presence_of :password

try
validates_presence_of :password, :allow_nil => true

It’s not in the api doc as it relates to this specific validator, but
it’s at the top of this page:

http://api.rubyonrails.com/classes/ActiveRecord/Validations/ClassMethods.html#M000813

David C. wrote:

try
validates_presence_of :password, :allow_nil => true

It’s not in the api doc as it relates to this specific validator, but
it’s at the top of this page:

http://api.rubyonrails.com/classes/ActiveRecord/Validations/ClassMethods.html#M000813

thanks david, but this will not work - I still get the “password can’t
be blank” error message

also, thus I use the same modell for creating a new user - than I really
need the validation - so I cant turn it off

I wonder why nobody else ran into that problem

andreas

i found a good resource
http://www.ruby-forum.com/topic/60002

On 11/6/06, David C. [email protected] wrote:

it’s at the top of this page:

http://api.rubyonrails.com/classes/ActiveRecord/Validations/ClassMethods.html#M000813

There’s also the :if option, documented in the link above.

Isak

Andreas S. wrote:

thanks david, but this will not work - I still get the “password can’t
be blank” error message

also, thus I use the same modell for creating a new user - than I really
need the validation - so I cant turn it off

I wonder why nobody else ran into that problem

andreas

validates_presence_of :password, :on => :create

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs