在Rails(Rails 4.0.0 rc2,ruby 1.9.3p429)中,在Gemfile中,我有以下行:
gem 'google-api-client', :require => 'google/api_client'
然后进行捆绑安装。
在控制器中:
require 'google/api_client'
class PagesController < ApplicationController
def home
@client = Google::ApiClient.new
end
end
如果我转到127.0.0.1:3000,我会出现以下错误:
NameError in PagesController#home
uninitialized constant Google::ApiClient
有人能告诉我如何在rails中集成ruby谷歌api吗?
感谢
它是APIClient.new.
@client = Google::APIClient.new
您还应该设置应用程序名称和版本号,否则在运行代码时会得到一个难看的stdout。像这样:
@client = Google::APIClient.new(:application_name => "MyApplication",:application_version => "0.1")