-2
我們收到此錯誤不能大規模指派保護的屬性:令牌
ActiveModel::MassAssignmentSecurity::Error in AuthenticationsController#create
Can't mass-assign protected attributes: token
在此之前,我們有令牌期滿,阻止我們的Web應用程序發佈,所以爲了解決這個問題,我們正在努力每次用戶使用提供者進行身份驗證時更新令牌和祕密屬性。
下面的代碼:
class AuthenticationsController < InheritedResources::Base
def create
omniauth = request.env['omniauth.auth']
authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
if authentication
user = User.find(authentication.user_id)
user.update_attributes(:token => omniauth["credentials"]["token"])
user.update_attributes(:secret => omniauth["credentials"]["secret"])
flash[:success] = "Signed in successfully"
sign_in_and_redirect user
elsif current_user
#rest of the code here#
這裏的架構
create_table "authentications", :force => true do |t|
t.integer "user_id"
t.string "provider"
t.string "uid"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "secret"
t.string "token"
end
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.timestamp "created_at", :null => false
t.timestamp "updated_at", :null => false
t.string "password_digest"
t.string "remember_token"
end
這裏的身份驗證模式
class Authentication < ActiveRecord::Base
belongs_to :user
attr_accessible :provider, :uid, :token, :secret
end
感謝您的回覆。任何想法爲什麼屬性沒有得到更新? – johbones 2013-04-11 08:47:37
您試圖更新用戶表中不存在的列(令牌和祕密)。 – benchwarmer 2013-04-11 08:51:38
我的意思是,任何想法爲什麼在將代碼更改爲'authentication.update_attributes'後,令牌和祕密列仍然沒有更新? – johbones 2013-04-11 16:58:32