Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8228555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:29:50+00:00 2026-06-07T16:29:50+00:00

I am building a prototype of a education application using Rails 3, omniauth and

  • 0

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:
enter image description here

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:29:52+00:00Added an answer on June 7, 2026 at 4:29 pm

    You can’t use p or puts in 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 puts inside this concatenation operation. So everything in the ERB file needs to be a string. The output from a puts call just ‘goes up in smoke’ since a puts call does not return a string, it writes to stdout instead.

    Next we look at group_by: it returns a Hash:

    ---------------------------------------------------- Enumerable#group_by
         enum.group_by {| obj | block }  => a_hash
    ------------------------------------------------------------------------
         Returns a hash, which keys are evaluated result from the block,
         and values are arrays of elements in enum corresponding to the key.
    
            (1..6).group_by {|i| i%3}   #=> {0=>[3, 6], 1=>[1, 4], 2=>[2, 5]}
    

    So putting everything together we could do something like this:

    <% current_user.friends.group_by(&:highschool_name).each do |hsname, friends| %>
       <% next if hsname.blank? %>
       <li><%= hsname %></li> 
       <% friends.each do |friend| %>
         <%= image_tag(friend.img_url) %> # <- Or wherever you get the img url from 
       <% end %>
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a web application (using prototype) that requires the addition of large chunks
i'm building a RoR app for facebook using FBML and the Prototype JavaScript library.
I'm building a prototype search application using CakePHP and I have a search controller
I'm building a prototype using Expression Blend 3 and SketchFlow (a Silverlight SketchFlow application
I'm building a little prototype app to test Location Services. My app uses both
Here is my scenario: I'm building a web application for an embedded system user
I am building an iPhone audio app using Audio Sessions. Prototype was functioning till
I am building a prototype of a windows phone 7 app using d:DesignData in
I've just started building a prototype application in Django. I started out by working
Good afternoon, We are building a prototype of a deduper. We are using a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.