1

validatable为我的应用启用了模块。在我要求用户的电子邮件地址进行注册时的屏幕上,如果电子邮件已经存在......这是我看到的错误:

We found 2 errors that prevented your account from being created:
Email has already been takenEmail has already been taken

这是来自日志:

Started POST "/users" for 127.0.0.1 at 2012-06-21 14:37:41 -0500
Processing by RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"zcpDH5U4XkHcYWVHEqrshgmzGiqsZHI9mD6Inrdr8uE=", "user"=>{"email"=>"abc@email.com"}, "commit"=>"Sign Me Up!"}
   (0.1ms)  begin transaction
  User Exists (0.2ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = 'abc@email.com' LIMIT 1
  User Exists (0.1ms)  SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('abc@email.com') LIMIT 1
   (0.1ms)  rollback transaction
  Rendered devise/shared/_links.erb (0.8ms)
  Rendered devise/registrations/new.html.erb within layouts/application (6.5ms)
Completed 200 OK in 1118ms (Views: 290.9ms | ActiveRecord: 0.0ms)

我如何通过尝试进行两次检查而只进行 1 次检查来获得它?

4

2 回答 2

0

试图登录,但它不会让我。

我不做 ruby​​,但看起来您可能正在输入一封符合这两个标准的电子邮件。可能只需要第二个。希望这可以帮助!

User Exists (0.2ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = 'abc@email.com' LIMIT 1
User Exists (0.1ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('abc@email.com') LIMIT 1

于 2012-06-21T21:22:13.837 回答
0

Rails 对每个验证运行单独的检查,因此存在和唯一性验证器将导致两次检查。如果您想避免多余的错误消息,您可以执行以下操作,并且只输出唯一的错误消息:

#error_explanation
  .alert.alert-error
    Please correct the following #{pluralize(object.errors.full_messages.uniq.size, "error")}:
   %ul
   - object.errors.full_messages.uniq.each do |msg|
     %li #{msg}
于 2012-12-19T01:33:16.563 回答