S3混淆了const_missing_from_s3_library错误

时间:2012-05-01 17:47:09

标签: ruby amazon-s3

我使用的是典型的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>'

我的文档几乎与规范有关,但我对此为何会如此困惑?

1 个答案:

答案 0 :(得分: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