我正在密切关注omniauth的railscast,但我收到了视频中没有遇到的这个错误
Can't mass-assign protected attributes: provider, uid
这是我创建的身份验证控制器
class AuthenticationsController < InheritedResources::Base
def index
@authentications = current_user.authentications if current_user
end
def create
omniauth = request.env['omniauth.auth']
authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
if authentication
flash[:notice] = "Signed in successfully"
sign_in_and_redirect(:user, authentication.user)
elsif current_user
current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
flash[:notice] = "Authentication successful"
redirect_to authentications_url
else
user = User.new
user.apply_omniauth(omniauth)
user.save(:validate=>false)
flash[:notice] = "Signed in successfully"
sign_in_and_redirect(:user, user)
end
end
def destroy
@authentication = current_user.authentications.find(params[:id])
@authentication.destroy
flash[:notice] = "Successfully destroyed authentication"
redirect_to authentications_url
end
end
这是我对 user.rb 的内容,我在查看过去的线程后添加了 :provider 和 :uid 到 attr_accessible
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation, :provider, :uid
has_many :authentications
不幸的是,当我尝试使用 Twitter (path = /auth/twitter/callback) 登录时,我仍然收到此错误