Question

I use Koala gem to access Facebook graph api and it returns a hash which I am trying to access my rails view. I get most other elements of the hash but the actions array continues to throw errors. I am sure I am not accessing it right. Here is the actions part of the response:

"actions"=>[{"name"=>"Comment", "link"=>"https://www.facebook.com/100000484957496/posts/849187568440734"}, {"name"=>"Like", "link"=>"https://www.facebook.com/100000484957496/posts/849187568440734"}]

I have the code:

<% @feed.each do |f| %>
<p><%= f["actions"][0]["name"] %></p>

and it throws error:

undefined method `[]' for nil:NilClass

I also tried without index

<p><%= f["actions"]["name"] %></p>

same error....

and with index in quotes

<p><%= f["actions"]["0"]["name"] %></p>

same error.

How do I access this element of the response hash?

Any help appreciated.

Was it helpful?

Solution

Probably your instance variable @feed is not accessing the right key.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top