ruby on rails - How to set Devise to require one of email or username to be populated for saving? -
i followed this: https://github.com/plataformatec/devise/wiki/how-to:-allow-users-to-sign-in-using-their-username-or-email-address
which works. can login either :username , :password or :email , :password.
however, when creating accounts in console, if leave email blank, validation error. apparently email still required create user.
i'd able create user using :username , :password, or :email , :password.
please try adding following user model:
def email_required? false end
you may need create migration allow email column on users table null ( in case not null-allowed column already):
change_column :users, :email, :string, :null => true
edit:
all have left ensure @ least username or email present. can setting following validation statement:
validate :username_or_email_is_present def username_or_email_is_present if self.username.blank && self.email.blank? errors.add(:base, "email or username must set") end end
Comments
Post a Comment