API를

2012-06-15 2 views
0

내가 접근 할 필요가 어디 레일 응용 프로그램을 구축하기 위해 노력하고있어 접속하기 Zomato APIAPI를

사람이 컨트롤러와 뷰를 생성하는 방법에 나를 인도 없습니다. 이 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 

내가보기에 응답 개체를 얻으려고 :

undefined method 'id' for ["id", 773]:Array 
: 그래서

<%= @response.each do |item| %> 
    <td><%= item.id %></td> 
    <td><%= item.name %></td> 
    <td><%= item.url %></td> 
<% end %> 

을,이 다음과 같은 오류를 보여줍니다

+0

[무엇을 시도해 봤습니까?] (http://whathaveyoutried.com/) – sczizzo

+1

[스택 오버플로는 개인 연구 비서가 아닙니다.] (http://meta.stackexchange.com/a/128553/133242) –

답변

0

REST API이므로 몇 개의 ActiveResource 클래스를 작성하여 활성 레코드와 매우 비슷하게 사용할 수 있습니다. ActiveResource 문서를 읽어보십시오.