我抓住值数据:名称,UID,highschool_name,graduateschool_name这样的:导轨 - 较好的流量控制 - 环
def add_friends
facebook.get_connections("me", "friends", :fields => "name, id, education").each do |hash|
self.friends.where(:name => hash['name'],
:uid => hash['id'],
:highschool_name => hash['education']['school']['name'] unless hash["education"].blank?,
:graduateschool_name => hash['education']['school']['name'] unless hash["education"].blank?).
first_or_create
end
end
从散列的数组:
"education": [
{
"school": {
"id": "110703012290674",
"name": "Kunskapsgymnasiet Malmö"
},
"year": {
"id": "136328419721520",
"name": "2009"
},
"type": "High School"
},
{
"school": {
"id": "112812485399398",
"name": "Malmö University"
},
"year": {
"id": "118118634930920",
"name": "2012"
},
"concentration": [
{
"id": "104076956295773",
"name": "Computer Science"
}
],
"type": "Graduate School",
"classes": [
{
"id": "165093923542525",
"name": "Programmering",
"description": "Kursen fokuserar på metoder och tekniker vid utveckling av webbapplikationer med hjälp av HTML5."
}
]
}
],
编辑: 这代码剂量工作。我想从这个哈希数组中选择所有的学校和研究生院并保存它。
我以前见过这个散列。 :)是不是我以前的答案对你有用?你在问别的吗? – 2012-07-09 22:53:27
@Sergio Tulentsev,我有但并非一样。我试图在这个方法上实现同样的tatice,但没有任何结果。 – SHUMAcupcake 2012-07-09 22:56:15
此代码不起作用,对吧?描述它究竟如何不起作用。你希望它做什么。 – 2012-07-09 22:59:31