我正在尝试使用新的Rails 6 syntax for downloading files复制附件文件>
if original.attachment.attached? original.attachment.open do |tempfile| clone.attachment.attach({ io: tempfile, filename: original.attachment.blob.filename, content_type: original.attachment.blob.content_type }) end end
我收到此错误:
IOError (closed stream)
如果在执行过程中检查/ tmp /文件夹,则将有tempfile副本。我不知道为什么会出现此错误。
我正在macOS 10.13 High Sierra上运行Rails 6.0.0和ruby 2.6.5p114
我正在尝试使用新的Rails 6语法来复制附件,如果original.attachment.attached是否使用了语法下载文件? original.attachment.open做| tempfile | clone.attachment.attach({...
好的,我找到了答案。在rails 6中,连接时必须再次打开临时文件,如下所示: