2

我使用的是典型的 Mac/Ruby 1.9.3p125

irb>

require 'aws/s3'
AWS::S3::Base.establish_connection!(:access_key_id => 'AccessKey',:secret_access_key => 'SecretKey' )
Service.buckets

(与 Bucket.find 或几乎任何东西都相同的错误!)

给我:

NameError: uninitialized constant Service
from ~/.rvm/gems/ruby-1.9.3-p125/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206
 :in `const_missing_from_s3_library'
from (irb):23
from ~/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `<main>'

我几乎按照规范遵循文档,但我很困惑为什么会这样?

4

1 回答 1

3

您需要在您的课程中包含 AWS::S3 或执行 AWS::S3.Service。

以下是一些代码示例:

require 'aws/s3'
class MyClass
  include AWS::S3
  AWS::S3::Base.establish_connection!(:access_key_id => 'AccessKey',:secret_access_key => 'SecretKey' )
  Service.buckets
end

或者

require 'aws/s3'
class MyClass
  AWS::S3::Base.establish_connection!(:access_key_id => 'AccessKey',:secret_access_key => 'SecretKey' )
  AWS::S3::Service.buckets
end
于 2012-05-01T20:33:11.210 回答