我有如下内容:
attachments.each do |a|
Rails.logger.info a.filename
tempfile = Tempfile.new("#{a.filename}", "#{Rails.root.to_s}/tmp/")
Rails.logger.info tempfile.path
end
附件来自Paperclip。
这是输出结果:
billgates.jpg
/Users/bhellman/Sites/cline/tmp/billgates.jpg20101204-17402-of0u9o-0
为什么文件名最后会附加上 20101204-17402-of0u9o-0
,这会导致使用 paperclip 等工具时出现问题。有人见过这种情况吗?我真的不知道是什么东西在做这件事情。
谢谢。
更新 Paperclip: Github 上的 Paperclip
a 是附件文件。
tempfile = Tempfile.new("#{a.filename}", "#{Rails.root.to_s}/tmp/")
tempfile << a.body
tempfile.puts
attachments.build(
:attachment => File.open(tempfile.path)
)