Accessing an API
Posted
by
Paritosh Praharaj
on Stack Overflow
See other posts from Stack Overflow
or by Paritosh Praharaj
Published on 2012-06-15T03:36:34Z
Indexed on
2012/06/16
3:16 UTC
Read the original article
Hit count: 258
ruby-on-rails
|httparty
I'm trying to build a Rails app where I have to access the Zomato API
Could anybody guide me on how to create the Controller and View. Suppose I want to get the name of the restaurant from this URL: Restaurant, how do I write the controller and views for it. Currently, I'm using HTTParty gem.
This is my controller code:
def restaurants
@response = HTTParty.get("https://api.zomato.com/v1/restaurant.json/773", :headers => {"X-Zomato-API-Key" => "MYAPIKEY"})
puts response.body, response.code, response.message, response.headers.inspect
@categories = Category.where(:category_name => 'Restaurants')
end
And I'm trying to get the response object in the view:
<%= @response.each do |item| %>
<td><%= item.id %></td>
<td><%= item.name %></td>
<td><%= item.url %></td>
<% end %>
So, this shows the following error:
undefined method 'id' for ["id", 773]:Array
© Stack Overflow or respective owner