我对我的User
模型进行了一些密码验证,以及create_with_omniauth
从用户的 Facebook 帐户获取信息的方法:
用户.rb:
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation
has_secure_password
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true,
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :password, presence: true, length: { minimum: 6 }
validates :password_confirmation, presence: true
def self.create_with_omniauth(auth)
create! do |user|
user.provider = auth["provider"]
user.uid = auth["uid"]
user.name = auth["info"]["name"]
user.email = auth["info"]["email"]
end
end
end
现在当我点击link_to "Sign in with Facebook, "auth/facebook"
我得到这个错误:
验证失败:密码不能为空,密码不能为空,密码太短(最少6个字符),密码确认不能为空
由于User
模型中的这两行:
validates :password, presence: true, length: { minimum: 6 }
validates :password_confirmation, presence: true
当用户尝试使用 OmniAuth 登录方法登录时,如何绕过该验证?