私はdeviseとdevise-token-authを使用します。私は、次の内容電子メールの妥当性検査を削除する
class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :authentication_keys => [:login]
include DeviseTokenAuth::Concerns::User
validates_uniqueness_of :login
validates_presence_of :full_name
protected
def email_required?
puts "email_required called"
false
end
end
とUserモデルを持っていますが、電子メールの検証を考案することは、まだ
2.3.0 :003 > user = User.new(login: "hello", password: "11111111", password_confirmation: "11111111", full_name: "hello world")
=> #<User id: nil, provider: "email", uid: "", email: nil, full_name: "hello world", login: "hello", created_at: nil, updated_at: nil>
2.3.0 :004 > user.valid?
email_required? called #<===== my method is called!
(3.7ms) SELECT COUNT(*) FROM "users" WHERE "users"."provider" = $1 AND "users"."email" IS NULL [["provider", "email"]]
User Exists (1.0ms) SELECT 1 AS one FROM "users" WHERE "users"."login" = $1 LIMIT $2 [["login", "hello"], ["LIMIT", 1]]
=> false
2.3.0 :005 > user.errors
=> #<ActiveModel::Errors:0x000000028e2338 @messages={:email=>[...]}, @details={:email=>[{:error=>:blank}]}>
なぜこれを働いていますか? ありがとう
これを試してください。 'email.rebired?'メソッドを 'user.rb'に移動 –
' email_required? 'は既に' user.rb'にあります – motoroller
'user.rb'から' protected'を削除します –