Accessing an API
- by Paritosh Praharaj
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