新手问题 怎么改 devise 中默认的 email 登录为 username?

dandan · 2015年07月07日 · 最后由 dandan 回复于 2015年07月07日 · 1984 次阅读

如题,谷歌了下找到 http://stackoverflow.com/questions/5343108/using-user-name-for-login-in-devise

可是不会按照这个上面改,求教,哪里找这个 base moudle?

#1 楼 @KoALa 不行 方便留 skype 或者微信不??

您的 这个 说话 方式 好 累

修改 config/devise.rb

# ==> Configuration for any authentication mechanism # Configure which keys are used when authenticating a user. The default is # just :email. You can configure it to use [:username, :subdomain], so for # authenticating a user, both parameters are required. Remember that those # parameters are used only when authenticating and not when retrieving from # session. If you need permissions, you should implement that in a before filter. # You can also supply a hash where the value is a boolean determining whether # or not authentication should be aborted when the value is not present.

config.authentication_keys = [:username]

#4 楼 @luolinae86 你好,这个已经修改了,可是单单这个修改不够啊~我参照了http://stackoverflow.com/questions/18026594/rails-4-devise-login-with-email-or-username-and-strong-parameters 这篇文章,可是还是出现了错误 undefined method `attr_accessible'

#3 楼 @alucardpj 恩恩,抱歉,这样会比较好点~

#4 楼 @luolinae86 搞定了,谢谢~!

需要 登录 后方可回复, 如果你还没有账号请 注册新账号