【发布时间】:2014-03-31 12:25:23
【问题描述】:
在上传到新目的地之前,我使用 Tempfile 存储生成的 PDF。
pdf_file = WickedPdf.new.pdf_from_string(msgbody)
tempfile = Tempfile.new(['Bob', '.pdf'], Rails.root.join('public','pdf-test'))
tempfile.binmode
tempfile.write pdf_file
tempfile.close
虽然这可以正常工作,但生成的文件名,例如 bob20140331-19260-1g6rzr1.pdf 对用户不友好。
我了解 Tempfile 会创建一个唯一的名称以及原因,但我最终需要更改名称以使其更直观/更易于用户理解。
有推荐的方法吗?即使它只是删除中间(19260)?感谢您的时间和帮助。
【问题讨论】:
-
您想通过什么方式获取名称?请举例
-
如果你想创建自己的临时文件名,那么就这样做吧。
标签: ruby filenames temporary-files