简体   繁体   中英

Accessing Koala Facebook Graph API Response in Rails

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.

您的实例变量@feed可能没有访问正确的键。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM