2013-04-11 6 views
-2

Мы получаем эту ошибкуНе удается массового правопреемником защищенные атрибуты: маркер

ActiveModel::MassAssignmentSecurity::Error in AuthenticationsController#create 
Can't mass-assign protected attributes: token 

До этого у нас были жетоны с истекающим сроком действия, не позволявшая объявление на нашем веб-приложение, поэтому для того, чтобы исправить это, мы пытаемся обновлять токены и секретные атрибуты каждый раз, когда пользователи аутентифицируются с помощью поставщика.

Вот код:

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 

ответ

2

Вы пытаетесь назначить маркер и секрет модели пользователя против делать это для модели аутентификации.

authentication.update_attributes(:token => omniauth["credentials"]["token"], :secret => omniauth["credentials"]["secret"]) 

должно работать.

+0

благодарит за ответ. любые идеи, почему атрибуты не обновляются? – johbones

+0

Вы пытались обновить столбцы (токен и секрет), которых нет в таблице пользователей. – benchwarmer

+0

Я имел в виду любую идею, почему токены и секретные столбцы все еще не обновляются после изменения кода на 'authentication.update_attributes'? – johbones

Смежные вопросы

 Смежные вопросы