1

I have module validatable enabled for my app. On a screen when I am asking for the user's email address for registration, if the email already exists...this is the error I see:

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

This is from the logs:

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)

How do I get it from trying to do two checks and just do 1?

marcamillion
  • 32,933
  • 55
  • 189
  • 380

2 Answers2

0

Was trying to log in but it wont let me.

I don't do ruby but it looks like you are probably entering in a email that meets the criteria for both of these. Probably only need the 2nd one. Hope this helps!

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

Rails runs separate checks for each validation, so a presence and a uniqueness validator will result in two checks. If you want to avoid the redundant error messages, you can do something like the below and only output unique error messages:

#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}
bigtex777
  • 1,150
  • 10
  • 15