Rails 3:路由错误 – 未初始化的常量MyController :: Google

我正在使用google-api-client gem( gem google-api-client, '0.4.1'在我的Gemfile中为gem google-api-client, '0.4.1' )。 以下代码导致错误uninitialized constant 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。

尝试添加:require => 'google/api_client' ,在:require => 'google/api_client'中指定google api客户端gem

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

这告诉捆绑商要求gem’google-api-client’的正确方法是require 'google/api_client'