我目前正在运行以下内容:
Rails 4.0.2
设计3.2.2
我已经在我的用户注册表单中添加了三个属性,并且根据Devise文档允许我的应用程序控制器中的Devise中的参数。
我现在的问题是,当我尝试注册时,我收到以下错误:
2个错误禁止此用户被保存 电子邮件不能为空白 密码不能为空
我已经在应用程序控制器中允许了其他参数,如下所示:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:first_name, :last_name, :profile_name, :email, :password, :password_confirmation) }
end
end
我的用户模型:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
最后我的注册表格:
<h2>Sign up</h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :first_name %><br />
<%= f.text_field :first_name, :autofocus => true %></div>
<div><%= f.label :last_name %><br />
<%= f.text_field :last_name %></div>
<div><%= f.label :profile_name %><br />
<%= f.text_field :profile_name %></div>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.label :password %><br />
<%= f.password_field :password %></div>
<div><%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %></div>
<div><%= f.submit "Sign up" %></div>
<% end %>
<%= render "devise/shared/links" %>
我尝试了两种不同的变体来允许其他参数,但我仍然收到相同的错误消息。我可以尝试任何想法吗?
谢谢
答案 0 :(得分:0)
运行gem uninstall protected_attributes
,然后运行bundle install
,然后重新启动rails服务器。
(我只是将sapmub发布在评论上面作为答案。感谢您的帮助sapmub!)