AnApprentice
AnApprentice

Reputation: 110950

How to process data from the facebook graph api in rails

I'm using the Koala gem to access the facebook graph api.

When I make a call I get back:

<%= @fb.inspect %>

Output:

[{"name"=>"Bob Jones", "id"=>"13223123112323"}] 

How do I access name?

@fb.id works for id but
@fb.name does not work?

Error:

undefined method `name' for [{.....

Ideas? Thanks

Upvotes: 0

Views: 257

Answers (1)

Joe Cannatti
Joe Cannatti

Reputation: 5079

It is an array of Hash objects.

@fb.first["name"]

You must get the first (in this case only) object for the array, and then get the value for the "name" key out from it.

Upvotes: 1

Related Questions