2012-02-16 33 views
3

我正在使用google-api-client gem(我的Gemfile中爲gem google-api-client, '0.4.1')。下面的代碼導致錯誤uninitialized constant MyController::GoogleRails 3:路由錯誤 - 未初始化的常量MyController :: Google

class MyController < ApplicationController 
    def index 
    @client = Google::APIClient.new 
    end 
end 

指定::Google::APIClient沒有幫助,錯誤然後說uninitialized constant Google

只需在文件頂部添加一個require 'google/api_client'就可以避免這種情況,所以看起來自動加載過程中出現錯誤。不知道這裏到底發生了什麼,指定Gemfile中的gem應該已經自動需要gem了,對吧?我已經重新啓動rails服務器btw。

回答

15

嘗試添加:require => 'google/api_client',你在Gemfile中

gem 'google-api-client', :require => 'google/api_client' 

這告訴打捆這要求創業板的正確方法「谷歌的API客戶端」是require 'google/api_client'

指定谷歌的API客戶端的寶石
相關問題