I'm trying to use the Yelp API to display a business' id
I installed the Yelp Gem as well as added my code to the initializer under 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.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
. 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:
response.businesses[0].id
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.