我使用omniauth-facebook并在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
但是auth.extra.raw_info.education|| { }, work: auth.extra.raw_info.work|| { }
,返回我是这样的:
---
- !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
我不知道是数组还是什么,我的教育领域是一个字符串,我如何访问学校、姓名、年份或类型?
如果我尝试auth.extra.raw_info.education.name
它说不可能将整数转换为字符串