Daniel Underwood
Daniel Underwood

Reputation: 2261

Uninitialized Constant GooglePlaces

I am currently using the google_places gem to try to access the places API. I am using the following code to get results:

class PlacesController < ApplicationController
  def index
    if params[:search]
        @client = ::GooglePlaces::Client.new(Rails.application.secrets.places_api_key)
        @places = @client.spots_by_query(params[:search])
    end
  end
end

I am running into an error of uninitialized constant GooglePlaces, which is replaced with PlacesController::GooglePlaces if I don't scope out. I believe this is a scoping issue, but nothing that I have tried fixes the issue. I am following the directions in the repo's readme and assuming that I don't have to include the source in the lib directory of my site. I can use the gem correctly from the rails console.

Upvotes: 0

Views: 384

Answers (2)

Shiva
Shiva

Reputation: 133

To use this API in rails application you need to use google_places gem.

add in gem file and run bundle install and restart the server once

gem 'google_places'

Next Create a project in google console and generate secret key .

https://code.google.com/apis/console

https://developers.google.com/places/documentation/

Finally restart the server

Upvotes: 1

Anthony
Anthony

Reputation: 15967

The docs said the API auth call should be:

@client = GooglePlaces::Client.new(Rails.application.secrets.places_api_key)

Upvotes: 0

Related Questions