我提交时收到此错误,但我无法弄清楚。因为参数发送正确
应用控制器
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! }
end
用户.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable
validates :role, inclusion: { in: ['player', 'team', 'fan'], message: "%{value} can be player, fan or team!" }
注册页面
<div><%= f.label :role %><br />
<%= f.select :role, ['fan', 'player'].map{|r| [t(r), r]} %>
<%= f.submit "Sign up" %>
注册页面(生成)
<select id="user_role" name="user[role]"><option value="fan">Fan</option>
<option value="player">Pro Player</option></select>
服务器日志
Started POST "/en/users" for 127.0.0.1 at 2013-07-10 23:47:35 +0200
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"6conUxB8E4y4Fy2pQ8WrT7ss/ykFqnuYzgoOkQIuSQY=", "user"=>{"email"=>"napster3000@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "role"=>"fan"}, "commit"=>"Sign up", "locale"=>"en"}
Unpermitted parameters: role
WARNING: Can't mass-assign protected attributes for User: email, password, password_confirmation
宝石文件
gem 'protected_attributes'
gem 'devise', "~> 3.0.0.rc", github: 'plataformatec/devise' #, branch: 'rails4'
gem 'responders', github: 'plataformatec/responders'
gem 'inherited_resources', github: 'josevalim/inherited_resources'
gem 'ransack', github: 'ernie/ransack', branch: 'rails-4'
gem 'activeadmin', github: 'gregbell/active_admin', branch: 'rails4'
gem 'formtastic', github: 'justinfrench/formtastic'