我正在關注的railscast爲omniauth相當密切,但我發現這個錯誤未在視頻不能大規模指派保護的屬性:供應商,UID(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:供應商和:uid來看着過去的線程
後attr_accessible不幸的是,我仍然收到此錯誤,當我嘗試使用Twitter(PATH = /認證/嘰嘰喳喳/回調)登錄
你應該加上'provider'和'uid'在'Authentication'模型,因爲ü調用方法'創造!'上這個模型 – Eru 2013-04-10 08:14:58
現在它在同一個控制器上給出一個'私有方法'apply_twitter'錯誤'。你知道爲什麼嗎? – johbones 2013-04-10 08:26:32
也許該方法是私人的,你從其他模型 – Eru 2013-04-10 08:32:08