The situation: You use Devise, and want to make emails optional because you login via username and why bother with emails?
Or maybe you want to be able to re-use email addresses as logins, say across subdomains. Or even multiple email addresses?
Your problem: Devise validatable hates on this and laughs are your attempts.
Keep the sweet Devise format validations, and customize devise validations by rolling your own
First, remove the :validatable argument from the devise method
1
| |
Then, you’ll need to implement your own validations. Depending on your intentions, either include or exclude validates_presence_of :email
1 2 3 4 5 | |
I know the above looks vaguely familiar… say: what you used to write all the time before Devise kicked in. But look at the devise validatable source – this is all it’s doing anyway.
To allow email re-use across accounts, add :scope=>:accont_id on the uniqueness validation.
Also cool: use the Devise.email_regexp and Devise.password_length to get good email validations.