我正在尝试使用回形针将文件上传到 s3 并在创建新对象并引用变量时出现此错误:
IE:
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
这是附件模型的样子:
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
最佳答案
原来是与我留在 gemfile 中的不同 s3 gem 冲突
关于ruby-on-rails - 带有 S3 on Rails 3 的回形针/未初始化的常量 AWS::S3::Connection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3613741/