51

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 it didn't work:

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

Do I have to define the validation two times?

Jakub Arnold
  • 85,596
  • 89
  • 230
  • 327

3 Answers3

66

By default, the validations run for both create and update. So it should be just:

validates_presence_of :password

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

bjnord
  • 2,734
  • 2
  • 23
  • 24
Alessandra Pereyra
  • 2,640
  • 18
  • 22
12

Only write:

validates_presence_of :password

No need...

on => :create
Jason Plank
  • 2,336
  • 5
  • 31
  • 40
FJ.
  • 129
  • 2
0

You can use this when you need to disable the validation on some specific operations, such as delete.

Ederson Badeca
  • 363
  • 1
  • 9