2014-07-15 59 views
0

我目前使用google_places gem來嘗試訪問場所API。我使用下面的代碼,得到的結果:未初始化的恆定GooglePlaces

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 

我遇到的uninitialized constant GooglePlaces一個錯誤,如果我不出去的範圍,其被替換爲PlacesController::GooglePlaces。我相信這是一個範圍問題,但我沒有嘗試解決這個問題。我遵循repo自述文件中的說明,並假設我不必將源代碼包含在我的站點的lib目錄中。我可以從導軌控制檯正確使用寶石。

回答

1

要使用在你需要使用GOOGLE_PLACES寶石Rails應用程序這個API。

加入寶石文件並運行包安裝並重新啓動一次

寶石「GOOGLE_PLACES」

下一頁創建谷歌控制檯中的項目,並生成密鑰服務器。

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

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

最後重新啓動服務器

+0

哇,我壓根沒想到要重新啓動服務器,因爲我通常不會有發展。這解決了這個問題。謝謝! – danielunderwood

+0

在配置文件發生任何更改後,我們需要重新啓動服務器 – Shiva

0

該文檔稱,API調用權威性應該是:

@client = GooglePlaces::Client.new(Rails.application.secrets.places_api_key) 
相關問題