Tip : Making email as optional (not mandatory) field in devise in Rails
August 4, 2016
No comments
Article
This situation arises, when we need to login through a different unique key other than email and wanted email to be optional in the entry form.
Prerequisites
Make sure in config/initializers/devise.rb to set the config.authentication_keys to some other field (not email, which is default) in devise.rb
1 2 3 4 |
# config.authentication_keys = [:email] config.authentication_keys = [:user_name] |
Now, let’s do
In the model rb (user.rb in my case) file,
1 2 3 4 5 6 7 8 9 |
def email_required? false end def email_changed? false end |
Categories: Ruby On Rails