简体   繁体   English

无法获得Yelp API在Rails中显示业务ID

[英]Can't get Yelp API to display Business ID in Rails

I'm trying to use the Yelp API to display a business' id 我正在尝试使用Yelp API来显示商家ID

I installed the Yelp Gem as well as added my code to the initializer under Yelp.rb 我安装了Yelp Gem,并将我的代码添加到Yelp.rb下的初始化程序中

client = Yelp::Client.new({ consumer_key: 'n8jpEPZJkbXwqAw',
                            consumer_secret: 'ABuZv6OW0iVTqPD5irr4',
                            token: 'AjYSuqleh0Ihb',
                            token_secret: 'wWaBdFu_dFXqbFc'
                          })

After that I went to a controller and added this 之后,我去了控制器并添加了这个

 def reviews
    Yelp.client.search(‘San Francisco’)

  end

I then tried to call the @reviews in the views and nothing is displaying 然后,我尝试在视图中调用@reviews,但没有显示任何内容

<%= @reviews.id %>

Any advice would be great thanks! 任何建议将不胜感激!

You need to save the response from the search call: 您需要保存来自搜索调用的响应:

response = Yelp.client.search('San Francisco')

Then you can access the results in the array of businesses returned in response . 然后,您可以访问以response返回的一系列业务中的结果。 For example, to get the rating of the first business returned: 例如,要获得返回的第一个业务的评级:

response.businesses[0].rating

You asked for the business ID, which of course is: 您要求提供企业ID,该ID当然是:

response.businesses[0].id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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