Zomato APIにアクセスする必要がある Rails アプリを構築しようとしています
コントローラーとビューの作成方法を教えてください。この URL からレストランの名前を取得したいとします: Restaurant、そのコントローラーとビューをどのように記述すればよいでしょうか。現在、HTTParty gem を使用しています。
これは私のコントローラコードです:
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
そして、ビューで応答オブジェクトを取得しようとしています:
<%= @response.each do |item| %>
<td><%= item.id %></td>
<td><%= item.name %></td>
<td><%= item.url %></td>
<% end %>
したがって、これは次のエラーを示しています。
undefined method 'id' for ["id", 773]:Array