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 9099983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:45:16+00:00 2026-06-17T00:45:16+00:00

I’m trying to learn the koala gem to link Facebook with my Ruby on

  • 0

I’m trying to learn the koala gem to link Facebook with my Ruby on Rails application. I’m starting to get the hang of it, but I’m running into some serious mental blocks!

def friends
  facebook.fql_query("SELECT uid,username, is_app_user, name, pic_square FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user=1");
rescue Koala::Facebook::APIError => e
  logger.info e.to_s
  nil
end

So, firstly, I’m using the FQL to search through a users friends. It returns a hash of details of users who are friends of current_user, the one signed into the app, and that have also connected with my application.

def friends_realname
  names = friends.select {|f| f["is_app_user"] }.map {|f| f["name"]}
  names.each { |name| puts name}
end

I’m selecting the above “user’s friends also using my app’s” names – and mapping them into an array. This returns an array: ["friend1's name", "friend2's name"]:

def friends_avatars
  @avatars = friends.select {|f| f["is_app_user"] }.map {|f| f["pic_square"]}
end

I’m trying to do the same, but returning the URLs of the profile pictures of those same users. It returns an array:

["http://www.example.com/example.jpg", "http://www.example2.com/example2.jpg"]

I want to format the information from the returned arrays. So, for the real names, instead of returning the actual array, I want to return a list of names. And, obviously for the images, instead of returning an array of image urls, I actually want to ‘puts’ those images out in the view.

I’m thinking that I need to iterate through each of these arrays, and then use the each method to do something with each string in the array, e.g., puts img_tag?

Would something like this be possible?:

def friends_avatars
  @avatars = friends.select {|f| f["is_app_user"] }.map {|f| f["pic_square"]}
  @avatars.each { |avatar| puts image_tag "#{avatar}}"}
end

Just realised that image_tag is a helper method, so I can’t use it there.

I’ve also tried this in a view file:

<% for url in @avatars do %>
  <%= puts "#{url}" %>
<% end %>

Which returns:

undefined method `each' for nil:NilClass

Anytime I try to return the strings within an array, they just return an array. Not really sure where to go from here.

  • 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-17T00:45:17+00:00Added an answer on June 17, 2026 at 12:45 am
    app_users = friends.select{ |f| f["is_app_user"] }
    @names_and_pictures = app_users.map{ |f| [ f["name"], f["pic_square"] ] }
    

    This creates an array of two-element arrays, i.e.

    [ [ "Bob", "http://foo" ], [ "Jim", "http://bar" ] ]
    

    Then you can iterate these in parallel:

    <% @names_and_pictures.each do |name,pic_url| %>
      <li><%=name%><img src="<%=pic_url%>"></li>
    <% end %>
    

    Note that you don’t use puts in your views, as this function outputs information to the console. Instead, you just use <%= ... %> to coerce Ruby code to be a string value and inject it at the appropriate spot in your output.


    Your original code is nice (insofar as you’ve wrapped your code in nicely-named methods) but does a little too much.

    def friends_realname
      names = friends.select {|f| f["is_app_user"] }.map {|f| f["name"]}
      names.each { |name| puts name}
    end
    

    There is no need to puts the names here. The method only happens to return the correct value because each returns the item that was just iterated. Your methods can be written just as effectively as:

    def friends_realname
      friends.select {|f| f["is_app_user"] }.map {|f| f["name"]}
    end
    
    def friends_avatars
      friends.select {|f| f["is_app_user"] }.map {|f| f["pic_square"]}
    end
    

    If you happen to want to keep these methods, you can combine two arrays into one by using Array#zip:

    names   = friends_realname               # One flat array
    avatars = friends_avatars                # Another flat array
    @names_and_pictures = names.zip(avatars) # An array of two-element arrays
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I upgraded downgraded to rails 2.3.17 due to the security bugs, but now I
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

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.