我正在尝试按高中分组用户朋友,用户使用他的 Facebook 帐户登录,我使用 Facebook 图表来获取他所有的朋友。
此处的代码首先输出/打印所有用户朋友,并按高中打印每个朋友的组。我不想要那个,我只希望它输出/打印组。
<ul class="friends-list">
<% current_user.friends.group_by(&:highschool_name).map do |hsname, friends| %>
<li><%= hsname %></li>
<% friends.map do |friend| %>
<%= image_tag(friend.image) %>
<% end %>
<% end %>
</ul>
用户表:
[id, name, image, location, highschool_name, highschool_year, college_name, college_year, graduteschool_name, graduate_year ]
朋友表:
[id, uid, name, image, higschool_name, college_name, graduateschool_name, user_id]
当前输出的详细信息:
Started GET "/users/1" for 127.0.0.1 at 2012-07-16 01:10:17 +0200
Processing by UsersController#show as HTML
Parameters: {"id"=>"1"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "1"]]
Rendered users/_profile_content.html.erb (0.6ms)
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
Friend Load (9.2ms) SELECT "friends".* FROM "friends" WHERE "friends"."user_id" = 1
Rendered users/show.html.erb within layouts/application (287.4ms)
Rendered layouts/_shim.html.erb (0.1ms)
Rendered layouts/_header.html.erb (2.3ms)
Rendered layouts/_footer.html.erb (0.6ms)
Completed 200 OK in 321ms (Views: 309.3ms | ActiveRecord: 9.8ms)
输出图像:http: //postimage.org/image/tgyl9f27n/