allenwq/devise-multi_email

Email validation not showing correct message

Opened this issue · 6 comments

Email validation always returns Email is invalid even when the email "has already been taken" (uniqueness validation).

Email validation should show "has already been taken"

@allenwq to clarify, when doing the following:

user.update(email: 'new@com.com')
user.errors.full_messages.first
=> "Email is invalid"

But when updating the email directly, you get the following:

email.update(email: 'new@com.com')
email.errors.full_messages.first
=> "Email has already been taken"

@swrobel Yes, I get it, this is a rails behaviour. we can fix it by propagating the email errors one level up. but i am not sure if we should leave the application to handle it... let me think.

@allenwq @ArthurWD does this do anything to fix this issue? #24

Seems to me like this issue is indeed fixed by #24.

I get this result:

user.update(email: 'new@com.com')
user.errors.full_messages.first
=> "Email has already been taken"

@ArthurWD wow, I didn't expect that.

@jeremylynch Can verify if this is still an issue?

@ArthurWD that's odd, I can't seem to replicate that behavior. I still get Email is invalid with latest master & Rails 5.2.0

Update: I'm able to get the same behavior that @ArthurWD sees by adding autosave: true to my emails association, ex:

has_many :emails, autosave: true

This doesn't require using the latest w/ ArthurWD's change merged.