Paperclip与Rails 3上的S3 / AWS :: S3 :: Connection未初始化常量

6
我正在尝试使用Paperclip将文件上传到S3,但在创建新对象并引用变量时出现以下错误:
  • 已安装aws-s3 gem
  • s3.yml文件具有正确的凭据
例如:
a = Attachment.new
a.file

NameError: uninitialized constant AWS::S3::Connection
    from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
    from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3.rb:32
    from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3.rb:31:in `class_eval'
    from /Library/Ruby/Gems/1.8/gems/aws-s3-0.6.2/lib/aws/s3.rb:31
    from /Library/Ruby/Gems/1.8/gems/paperclip-2.3.3/lib/paperclip/storage.rb:131:in `extended'
    from /Library/Ruby/Gems/1.8/gems/paperclip-2.3.3/lib/paperclip/attachment.rb:269:in `extend'
    from /Library/Ruby/Gems/1.8/gems/paperclip-2.3.3/lib/paperclip/attachment.rb:269:in `initialize_storage'
    from /Library/Ruby/Gems/1.8/gems/paperclip-2.3.3/lib/paperclip/attachment.rb:51:in `initialize'
    from /Library/Ruby/Gems/1.8/gems/paperclip-2.3.3/lib/paperclip.rb:372:in `new'
    from /Library/Ruby/Gems/1.8/gems/paperclip-2.3.3/lib/paperclip.rb:372:in `attachment_for'
    from /Library/Ruby/Gems/1.8/gems/paperclip-2.3.3/lib/paperclip.rb:270:in `file'
    from (irb):6

这是 Attachment 模型的样式:

class Attachment < ActiveRecord::Base
  belongs_to :post

  has_attached_file :file,
    :storage => :s3,
    :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
    :path => "/uploads/:attachment/:id/:style/:basename.:extension",
    :bucket => 'bucketname',
    :s3_permissions => :public_read
end
2个回答

1

Mike,你在Rails 3上成功地使用aws-s3了吗?我假设是的,但你能验证一下吗?因为我需要自己检查。


1
没问题,一切都很顺利,只要确保你的gemfile中没有另一个S3 gem,否则你可能会遇到我遇到的错误。 - miketucker
感谢您的跟进 @miketucker,非常感激。 - m7d

1

原来是与我在Gemfile中留下的另一个S3 gem发生了冲突


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接