validate email format only if not blank Rails 3

后端 未结 3 1463
庸人自扰
庸人自扰 2020-12-14 00:27

I want to validate the email only if the email has been entered.

I tried the following:

validates :email, :presence => {:message => \"Your emai         


        
3条回答
  •  情话喂你
    2020-12-14 00:36

    This should do the trick.

    validates :email,:presence => {:message => "Your email is used to save your greeting."}, :allow_blank => true,:uniqueness => { :case_sensitive => false } 

    Use:allow_blank => true or :allow_nil => true, :if => :email?

    edit: fix typo.

提交回复
热议问题