我抓住值數據:名稱,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