I am building a prototype of a education application using Rails 3, omniauth and the facebook graph api. So when a User log in to my application he uses his facebook account, I grab all his education history and his friends education_history.
I would like to group every User friends education likes this:

I have tried something like this:
<ul class="friends-list">
<%= current_user.friends.group_by(&:highschool_name) do |highschool_name|
p "<li>#{highschool_name}</li>"
end
%>
</ul>
And I get a syntax error.
The User tabel look like this:
[id, name, image, location, highschool_name, highschool_year, college_name, college_year, graduteschool_name, graduate_year ]
And the Friend tabel looks like this:
[id, uid, name, image, higschool_name, college_name, graduateschool_name, user_id]
How do solve my problem using active record, without loops because their are not effectivity.. right?
You can’t use
porputsin ERB files. Think of ERB files as one big string concatenated together. Like"string 1" + "string 2" + "string 3".That’s all ERB does – it just pastes strings together into one big string. You can’t call
putsinside this concatenation operation. So everything in the ERB file needs to be a string. The output from aputscall just ‘goes up in smoke’ since aputscall does not return a string, it writes tostdoutinstead.Next we look at
group_by: it returns aHash:So putting everything together we could do something like this: