views:

1348

answers:

3

If I want to have validation only on create, then I can do

validates_presence_of :password, :on => :create

but how do I say on create and update? I tried this but didn't work.

validates_presence_of :password, :on => [ :create, :update ]

Do I have to define the validation two times?

+6  A: 

As default, the validations will run themselves at create and update. So it should be just

validates_presence_of :password

The :on key just allows you to choose one of them.

Yaraher
A: 

Happens by default on save.

:on - Specifies when this validation is active (default is :save, other options :create, :update).

I haven't tried giving more options try giving with {} like :on => { :create, :update }

Umesh
{} in Ruby indicates a Hash, not an array. Your example contains incorrect syntax.
hgimenez
A: 

Only write:

validates_presence_of :password

No need...

on => :create

regards

FJ