开发者

Devise's validateable module doesn't respect custom defined email_required? method

开发者 https://www.devze.com 2023-01-25 19:36 出处:网络
So far as I can tell, in ord开发者_运维百科er to use the validateable module, but selectively disable the email field\'s validations, you must define a protected method email_required? on your model a

So far as I can tell, in ord开发者_运维百科er to use the validateable module, but selectively disable the email field's validations, you must define a protected method email_required? on your model and have it return false.

I've done this, but it appears the email validation is still triggered. Is this a bug in devise, or am I missing a crucial step?

Below are the relevant parts of my User model:

class User < ActiveRecord::Base
    devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable

    protected
      def email_required?
        false 
      end
end


In case anyone is still running into this, it has been added--but I believe only in the 1.2 branch. Download and install the 1.2rc and you can skip email validation as done in the question.

https://github.com/plataformatec/devise

0

精彩评论

暂无评论...
验证码 换一张
取 消