我使用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
,则说不可能将整数转换为字符串
答案 0 :(得分:1)
如果您正确使用omniauth,则数据应已在内部转换为哈希值
(确保auth
为env["omniauth.auth"]
)
要获得第一个学校名称,请使用:
auth.extra.raw_info.education[0].school.name