我是 Rails 的新手——使用带有设计 3.0.0rc 的 Rails 4 final(兼容 rails 4)。我进行了适当的配置并且注册工作正常,但是在尝试创建新用户(或编辑现有用户的个人资料)时,我开始收到 Unpermitted parameters: first_name, last_name 错误。关于这个主题有一些类似的问题,但对于不受支持的 Devise 版本 - 我的配置最初工作正常。
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"+DG4aeMPteQ4Mq9pPJ2JaitTVgp0NCW9nXi2qSv23zw=", "user"=>{"first_name"=>"John", "last_name"=>"Kenn", "email"=>"me1@email.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign Up"}
Unpermitted parameters: first_name, last_name
(0.2ms) BEGIN
User Exists (0.4ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = 'me1@email.com' LIMIT 1
(0.2ms) ROLLBACK
用户.rb
class User < ActiveRecord::Base
has_many :jobrecords, dependent: :destroy
# after_create :send_welcome_email
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :omniauthable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
validates :first_name, presence: true
validates :last_name, presence: true
validates :email, presence: true
attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :remember_me
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.first_name = auth.info.nickname
user.last_name = auth.info.nickname
end
end
def self.new_with_session(params, session)
if session["devise.user_attributes"]
new(session["devise.user_attributes"], without_protection: true) do |user|
user.attributes = params
user.valid?
end
else
super
end
end
def password_required?
super && provider.blank?
end
def update_with_password(params, *options)
if encrypted_password.blank?
update_attributes(params, *options)
else
super
end
end
private
def send_welcome_email
UserMailer.signup_confirmation(self).deliver
end
end
尽管它之前工作正常,但我尝试覆盖registrations_controller.rb 中的sign_up_params,但没有奏效。我仍然可以使用 openauth-twitter 进行注册(因为该应用在通过 twitter 注册时不要求输入名字或姓氏)。任何帮助表示赞赏。