gpt4 book ai didi

ruby-on-rails - 无法删除有关 case_sensitive 的警告

转载 作者:行者123 更新时间:2023-12-04 13:34:16 28 4
gpt4 key购买 nike

当我使用 rspec 进行测试时,每次都会显示以下警告。

DEPRECATION WARNING: Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1. To continue case sensitive comparison on the :email attribute in User model, pass `case_sensitive: true` option explicitly to the uniqueness validator. (called from block (2 levels) in <main> at /usr/src/app/spec/models/user_spec.rb:6)
所以我试着把它写到 User.rb(我希望不区分大小写)。

validates :email, uniqueness: { case_sensitive: false }


但是,警告无法删除。
接下来,我检查了 devise.rb(因为我使用了 devise 和 devise_token_auth)。在 devise.rb 中,它是关于 case_insensitive 的。

config.case_insensitive_keys = [:email]


供你引用...
用户名
# frozen_string_literal: true

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
include DeviseTokenAuth::Concerns::User
has_many :schedules

validates :name, presence: true, length: { maximum: 10 }
validates :email, uniqueness: { case_sensitive: false }
end

设计文件
Devise.setup do |config|
config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'

require 'devise/orm/active_record'

config.case_insensitive_keys = [:email]

config.strip_whitespace_keys = [:email]

config.skip_session_storage = [:http_auth]

config.stretches = Rails.env.test? ? 1 : 11

config.reconfirmable = true

config.expire_all_remember_me_on_sign_out = true

config.password_length = 6..128

config.email_regexp = /\A[^@\s]+@[^@\s]+\z/

config.reset_password_within = 6.hours
config.sign_out_via = :delete

end

为什么 Rails 不会停止 WARNING?
谢谢你的帮助。

最佳答案

您应该可以在 User.rb 中更改

#User.rb

class User < ActiveRecord::Base
...
# From
validates :email, uniqueness: { case_sensitive: false }
# To
validates_uniqueness_of :email, case_sensitive: true
end

关于ruby-on-rails - 无法删除有关 case_sensitive 的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63165940/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com