尝试访问不存在的字段(OmniAuth和Rails)

时间:2015-03-24 00:55:20

标签: ruby-on-rails facebook facebook-graph-api ruby-on-rails-4 omniauth

我对rails非常陌生,我尝试使用omniauth-facebook gem初始化用户登录时遇到错误。我的浏览器上读取的错误是

{"message"=>"(#100) Tried accessing nonexisting field (education_history) on node type (User)", "type"=>"OAuthException", "code"=>100}: {"error":{"message":"(#100) Tried accessing nonexisting field (education_history) on node type (User)","type":"OAuthException","code":100}}

但是,我项目中唯一存在的education_history是我为向用户添加名为education_history的列而进行的迁移...

在我的User模型中,我有一个方法:

def self.from_omniauth(auth)
    where(provider: auth.provider, uid: auth.uid).first_or_initialize.tap do |user|
      user.provider = auth.provider
      user.uid = auth.uid
      user.first_name = auth.info.first_name
      user.last_name = auth.info.last_name
      user.birthday = auth.extra.raw_info.birthday
      user.education_history = auth.extra.raw_info.education
      user.oauth_token = auth.credentials.token
      user.oauth_expiry_date = Time.at(auth.credentials.expires_at)
      user.save!
    end
  end

将在用户创建新会话时调用... 。 我的omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, Rails.application.secrets.facebook_key, Rails.application.secrets.facebook_secret,
            scope: "email,user_birthday,user_work_history,,user_education_history,user_location", display: "popup", image_size: { width: "50", height: "50"},
            info_fields: "first_name,last_name,email,birthday,education"
end

此处为我的用户Schema

create_table "users", force: :cascade do |t|
    t.string   "provider"
    t.string   "uid"
    t.string   "first_name"
    t.string   "last_name"
    t.string   "oauth_token"
    t.datetime "oauth_expiry_date"
    t.datetime "created_at",        null: false
    t.datetime "updated_at",        null: false
    t.string   "birthday"
    t.string   "email"
    t.string   "gender"
    t.string   "location"
    t.string   "education_history"   
end

我不知道在哪里开始调试此错误。请帮忙:(

0 个答案:

没有答案