【发布时间】:2011-08-02 21:40:17
【问题描述】:
我正在尝试使用 Heroku、Paperclip 和 S3 做一些非常简单的事情 - 将一个模型的附件设置为等于另一个模型的附件。
这是我整理的一个自定义 rake 任务:
task :migrate => :environment do
@companies = Company.where("attachment_file_name IS NOT NULL")
@companies.each do |c|
if c.attachments.where("attachment_file_name = ?", c.attachment_file_name).blank?
# i.e. if there are no instances of Attachment that match c.attachment
a = Attachment.new( :company_id => c.id, :name => "Default" )
a.attachment = c.attachment
a.save
end
end
end
所以,我正在尝试将 Company.attachment 移动到新 Attachment 模型的新实例。在我的本地开发服务器上,它运行良好。
一旦推送到 Heroku,我收到以下错误,指向 a.attachment = c.attachment 行。
The specified key does not exist.
我为在 heroku 控制台中有附件的公司手动尝试操作,我得到:
TypeError: can't convert nil into String
/app/.bundle/gems/ruby/1.8/gems/paperclip-2.3.6/lib/paperclip/storage/s3.rb:131:in `extname'
/app/.bundle/gems/ruby/1.8/gems/paperclip-2.3.6/lib/paperclip/storage/s3.rb:131:in `to_file'
/app/.bundle/gems/ruby/1.8/gems/paperclip-2.3.6/lib/paperclip/attachment.rb:81:in `assign'
/app/vendor/plugins/paperclip/lib/paperclip.rb:245:in `attachment='
你知道这里发生了什么吗?
我刚试过c.attachment = c.attachment。同样的错误!!!
【问题讨论】:
-
在黑暗中拍摄,但您是否尝试过使用
read_attribute来读取c.attachment属性...比如a.attachment = c.read_attribute(:attachment)?我之前不得不使用 CarrierWave 来获取图像属性,因为他们在幕后做了一些奇怪的事情,所以它可能与 PaperClip 的方式相同 -
@iWasRobbed - 我刚刚在 Heroku 控制台中尝试过,但它返回了
nil值。 -
你找到解决办法了吗?
-
我知道它不应该,但是 c.attachment.errors 包含什么有趣的东西吗? rdoc.info/github/thoughtbot/paperclip/master/Paperclip/…
标签: ruby-on-rails ruby-on-rails-3 amazon-s3 heroku paperclip