[英]rails accessing value from facebooker hash/array
This is my first time using the facebooker plugin with rails, and I'm having trouble accessing user info. 这是我第一次使用带Rails的facebooker插件,但无法访问用户信息。 The website uses FB connect to authenticate users. 该网站使用FB connect来验证用户身份。
I am trying to get the name of the university that the logged in user attends. 我正在尝试获取已登录用户参加的大学的名称。
When I use the command <%= facebook_session.user.education_history[:name] %>
, I get an error "Symbol as array index". 当我使用命令<%= facebook_session.user.education_history[:name] %>
,出现错误“符号作为数组索引”。
I have also tried using education_history[1
], but that just returns "# Facebooker::EducationInfo:<some sort of alphanumeric hash value>
" 我也尝试过使用education_history[1
],但是只返回“ Facebooker::EducationInfo:<some sort of alphanumeric hash value>
”
When I use something like <%= facebook_session.user.relationship_status %>
, it returns the relationship status just fine. 当我使用<%= facebook_session.user.relationship_status %>
类的东西时,它会返回关系状态。 Similarly, <%= facebook_session.user.hometown_location.city %>
returns the city name just fine. 同样, <%= facebook_session.user.hometown_location.city %>
返回的城市名称也很好。
I've checked out the documentation for facebooker, but I can't figure out the correct way to get the values I need. 我已经查看了facebooker的文档,但是无法弄清楚获取所需值的正确方法。
Any idea on how to get this to work? 关于如何使它起作用的任何想法吗?
Thanks! 谢谢!
facebook_session.user.education_history
returns an array of Facebooker::EducationInfo
objects. facebook_session.user.education_history
返回一个Facebooker::EducationInfo
对象的数组。 The proper way to access it would be: 访问它的正确方法是:
ed = facebook_session.user.education_history.last #Will be nil if not provided
@ed_name = ed.name unless ed.nil?
I am not sure the order they are sorted in, so you may need to call .first
instead of .last
我不知道他们的排序顺序,所以你可能需要调用.first
代替.last
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.