2

I use omniauth-facebook and get information about users with this function in user.rb

def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
  user = User.where(:provider => auth.provider, :uid => auth.uid).first
  unless user
    user = User.create(name: auth.extra.raw_info.first_name,
                       surname: auth.extra.raw_info.last_name,
                       provider: auth.provider,
                       uid: auth.uid,
                       email: auth.info.email,
                       password: Devise.friendly_token[0, 20],
                  #   City: auth.extra.raw_info.location.name,
                      state: auth.extra.raw_info.locale.gsub(/_/, '-'),

                       gender: auth.extra.raw_info.gender,
                       language: auth.extra.raw_info.language|| { },
                       bio: auth.extra.raw_info.bio|| { },
                       work: auth.extra.raw_info.work|| { } ,
                       education: auth.extra.raw_info.education|| { })
    end                   
  user
end

but auth.extra.raw_info.education|| { }, work: auth.extra.raw_info.work|| { } , returns me something like this:

  ---
  - !ruby/hash:OmniAuth::AuthHash
  school: !ruby/hash:OmniAuth::AuthHash
  id: '115686675112108'
  name: istituto magistrale
  type: High School
  - !ruby/hash:OmniAuth::AuthHash
  school: !ruby/hash:OmniAuth::AuthHash
  id: '134968379850136'
  name: laurea in pedagogia
  year: !ruby/hash:OmniAuth::AuthHash
  id: '116957165019970'
  name: '1986'
  type: College

I do not know if it is an array or what, my field of education is a string, how do I access school, name, year or type?

If I try auth.extra.raw_info.education.name it says impossible convert integer to string

4

1 に答える 1

1

authomn​​iauth を正しく使用している場合、データは既に内部でハッシュに変換されているはずですenv["omniauth.auth"](必ず .

最初の学校名を取得するには、次を使用します。

auth.extra.raw_info.education[0].school.name

于 2013-05-24T15:30:14.303 に答える