Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove email field in devise gem?

I would like to NOT require email for signing only mobile number to register user and login in using devise gem. I removed email from config/initializers/devise.rb:

like image 548
Vivek Dabhi Avatar asked Jan 04 '23 12:01

Vivek Dabhi


1 Answers

This is the link to the validate.rb file of devise. You can see a method email_required? in the model. So I guess

 def email_required?
    false
 end

You need to put above method in your model.rb file.

You'll also need to make a slight modification to your users table. By default, Devise does not allow the email field to be null. Create and run change a migration that allows email to be null

 # in console
 rails g migration AddChangeColumnNullToUserEmail

 # migration file
class AddChangeColumnNullToUserEmail < ActiveRecord::Migration
  def self.up
    change_column :users, :email, :string, :null => true 
  end

  def self.down
    change_column :users, :email, :string, :null => false 
  end
end
like image 55
Divyang Hirpara Avatar answered Jan 13 '23 08:01

Divyang Hirpara