设计:用替代方式替换“电子邮件”以登录 [英] Devise: Replace 'email' with alternative for sign in
问题描述
我试图在整个应用程序中使用Sublime的所有文件替换功能中的电子邮件
替换 accountnumber
。
I tried to replace email
with accountnumber
throughout my whole application using Sublime's "replace in all files" feature.
我重置并重新迁移了数据库,但是,注册时仍然会收到以下错误:
I've reset and re-migrated the DB, however, when registering I still get the following error:
undefined method `email' for #<Account:0x415b690>
然后以下参数
{"utf8"=>"✓",
"authenticity_token"=>"2qqA7dx99hx+VqkZGDmySNJd+2Fzxuanegy1ysrpD30=",
"account"=>{"accountnumber"=>"1307",
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]"},
"commit"=>"Sign up"}
有没有人有这个困难?
推荐答案
使用Devise,惯例是使用email进行登录,您正在使用gem(Devise),所以并不是所有的代码都可见在您的项目中,替换accountnumber用于电子邮件的搜索替换是不够的。您必须通过更改您的帐户模型来重新配置Devise。
With Devise, the convention is to use 'email' for sign in. You're using a gem (Devise), so not all the code is visible in your project, and a search-and-replace to substitute 'accountnumber' for 'email' is not enough. You have to reconfigure Devise by making changes to your Account model.
请确保在迁移Devise创建的(DeviseCreateUsers)中将电子邮件更改为accountnumber运行 rake db:migrate:reset
。
Be sure to change 'email' to 'accountnumber' in the migration Devise created ('DeviseCreateUsers') and run rake db:migrate:reset
.
更改您的帐户模型:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:authentication_keys => [:accountnumber]
def email_required?
false
end
def email_changed?
false
end
end
确保您已经在视图文件中生成了Devise视图并将电子邮件更改为accountnumber。
Make sure you've generated Devise views and changed 'email' to 'accountnumber' in the view files.
我已经写了一个 Rails Devise教程,这将有助于您了解Devise的工作原理。
I've written a Rails Devise Tutorial that will help you understand how Devise works.
这篇关于设计:用替代方式替换“电子邮件”以登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!