Rails 4 + Devise 3.0.0添加用户名 [英] Rails 4 + Devise 3.0.0 Adding Username

查看:153
本文介绍了Rails 4 + Devise 3.0.0添加用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 4和Devise 3.0.0,并且是使用这些新的强大参数的新手。我使用 Devise wiki上的文档。我遇到的问题是Rails 4中的强参数变化。

I'm working with Rails 4 and Devise 3.0.0 and am new to using these new strong paramters. I added a username to the User model using the documentation on the Devise wiki. The problem I'm running into is the strong parameters change in Rails 4.

如何添加:login 属性到用户模型以启用使用用户名或电子邮件登录?

How do I add the :login attribute to the user model to enable logging in with either the username or email?

推荐答案

从devise的rails4自述文件: a href =https://github.com/plataformatec/devise/tree/rails4#strong-parameters =noreferrer> https://github.com/plataformatec/devise/tree/rails4#strong-parameters

From the rails4 readme on devise: https://github.com/plataformatec/devise/tree/rails4#strong-parameters

class ApplicationController < ActionController::Base
  before_filter :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :email) }
  end
end

这篇关于Rails 4 + Devise 3.0.0添加用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆