How to disable email validation in rails device [closed]

。_饼干妹妹 提交于 2019-12-13 11:27:35

问题


I need you help

Try: model/user.rb link to source

but it does not work


回答1:


Simply comment out the line specifying validators for the email attribute, or remove it altogether:

# app/models/user.rb
# validates :email, :presence => false, :email => false

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



回答2:


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

in your User model should remove the necessity while registering.




回答3:


From this question, I guess, your email field is not required field. IF this, Try just remove the code: :validatable from your user.rb mudel.



来源:https://stackoverflow.com/questions/17021367/how-to-disable-email-validation-in-rails-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!