Reputation: 141
I have a model, User:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable, :trackable
include DeviseTokenAuth::Concerns::User
extend EncryptedField
validates :email, uniqueness: true, allow_nil: true
validates :mobile,
presence: true,
uniqueness: true,
phone: { possible: false, types: [:mobile], allow_blank: false }
end
On sign_up on postman
:
At route localhost:3000/auth
with body:
{
"first_name": "RaghJhu",
"last_name": "Deesp",
"mobile": "+91 9726544141",
"answer": "Yes1",
"email": "apoorewewewewdedgcom",
"password": "Password@123#",
"provider": "mobile",
"password_confirmation": "Password@123#"
}
returns response User created.
email
is not a required field.
I have also defined email_regexp in config/initializers/devise.rb
:
config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
Can you tell me why it is not validating email?
Upvotes: 0
Views: 364
Reputation: 81
please set below email validation:
validates_format_of :email, with: URI::MailTo::EMAIL_REGEXP
Upvotes: 1