Rails model validation on create and update only

前端 未结 3 773
不思量自难忘°
不思量自难忘° 2020-12-08 09:04

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

validates_presence_of :password, :on => :create
<         


        
相关标签:
3条回答
  • 2020-12-08 09:55

    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.

    0 讨论(0)
  • 2020-12-08 10:05

    Only write:

    validates_presence_of :password
    

    No need...

    on => :create
    
    0 讨论(0)
  • 2020-12-08 10:06

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

    0 讨论(0)
提交回复
热议问题