Rails:如何在Heroku上使用系统zip从xml模板制作docx?

我在本地工作,将模板文件存储在#{Rails.root}/tmp ,使用system "cd tmp/template; zip -r ../#{@filename} *"压缩文件,发送文件。 docx(zip存档)到S3然后再到浏览器。 问题是Heroku没有找到文件。 在创建xml文件之前,我从另一个位置复制模板目录( system "cp -R support/ser_template tmp/" )。 我理解Heroku的只读文件系统,但是我不能让#{Process.pid}乱丢我的文件名(Word要求将xml文件命名为document.xml)。

无论如何,我可以将模板文件存储在亚马逊上并仍使用Heroku的系统zip实用程序吗? RubyZip不会创建正确的docx存档 。

编辑:这是代码:

 require 'aws/s3' class WordDocument include ConnectS3 def initialize(content) connect_s3 @pid = Process.pid @filename = "SER_" + Time.now.strftime("%Y%m%d-%H%M%S") + '.docx' system "cp -R #{Rails.root}/support/ser_template #{temp_path}" xml = File.open(xml_path, 'w') xml.puts content xml.close system "cd #{temp_path}; zip -r #{@filename} *" docx = File.open(temp_path + "/" + @filename, 'r') AWS::S3::S3Object.store(s3_path, docx, @s3_credentials["bucket"], :use_virtual_directories => true) AWS::S3::S3Object.grant_torrent_access_to s3_path, @s3_credentials["bucket"] end def temp_path "#{Rails.root}/tmp/#{@pid}_ser" end def xml_path temp_path + "/word/document.xml" end def path "https://s3.amazonaws.com/" + @s3_credentials["bucket"] + s3_path end def s3_path '/section_editor_reports/' + @filename end end 

你不能只在#{Rails.root}/tmp调用一个创建目录,比方说, #{Process.pid}_docx/something_nice/ ? 复制(或符号链接)您需要的内容:

 #{Rails.root}/tmp/#{Process.pid}_docx/something_nice/ 

然后

 system "cd #{Rails.root}/tmp/#{Process.pid}_docx/; zip -r x.zip something_nice" 

然后你有:

 #{Rails.root}/tmp/#{Process.pid}_docx/x.zip 

有一个漂亮的内部结构,不包括你的PID。