[英]Devise 3 Rails 4 Unpermitted parameters
这是我注册时得到的: Unpermitted parameters: password_confirmation WARNING: Can't mass-assign protected attributes for User: email, password
我已经安装了所有内容,并且正在尝试首次设计。 我已经创建了一个模型用户,一切应该顺利。 这是设计初次用户注册的全新安装。 没有默认代码已被更改。 请帮忙!
解决的问题:我向user.rb模型添加了attr_accessible
检查您的用户模型,并查看参数是否可访问。
请记住,您不需要命名它们,即IE我的用户模型如下所示,带有设计3和导轨4:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
validate :username, presence: true, uniqueness: true, format: { with: /[a-zA-Z0-9]{4,20}/ }
end
解决方案Rahul谈论的问题没有多大意义,因为请求中已经允许使用这些参数,但是就我而言,我为该User模型提供了一个额外的username属性,因此我将其添加到ApplicationController中:
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:account_update) << :username
devise_parameter_sanitizer.for(:sign_up) << :username
end
在您的ApplicationController中添加以下内容(如果您有Rails4)
before_filter :update_sanitized_params, if: :devise_controller?
# method to sanitized params for devise user sign up
def update_sanitized_params
devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:email,:password, :password_confirmation)}
end
有关更多信息,请参见https://github.com/plataformatec/devise#getting-started的 “严格参数”部分
如果还有其他人仍然出现此错误,请检查您的表单URL路径。 我已经将session_path复制到应该使用registration_path的表单中。
我正在本练习中首次使用Devise GEM(目前正在学习Rails)。 就我而言,我有同样的错误,这是一个路由问题。
问题出在new.index.html.erb
devise/registrations
视图文件夹的new.index.html.erb
中的form_for
上。
该表单具有url: session_path(resource_name)
,但是为了起作用,它应该指向registration_path(resource_name)
。
我改变了它,现在它在heroku上工作了。
这是文件的链接。
这是heroku上的练习: devise.muga.com.co
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.