Note that there are some explanatory texts on larger screens.

plurals
  1. PORails: How can I use system zip on Heroku to make a docx from an xml template?
    text
    copied!<p>I have this working locally, storing the template files in <code>#{Rails.root}/tmp</code>, using <code>system "cd tmp/template; zip -r ../#{@filename} *"</code> to zip up the files, sending the .docx (zip archive) to S3 and then to the browser. The problem is that Heroku is not finding the files. Before I create the xml file, I am copying the template directory from another location (<code>system "cp -R support/ser_template tmp/"</code>). I understand Heroku's <a href="http://devcenter.heroku.com/articles/read-only-filesystem" rel="nofollow">read-only filesystem</a> but I can't have <code>#{Process.pid}</code>'s littering my filenames (Word requires the xml file to be named document.xml).</p> <p>Is there anyway I can store the template files on Amazon and still use Heroku's system zip utility? <a href="http://tomasvarsavsky.com/2009/04/04/simple-word-document-templating-using-ruby-and-xml/" rel="nofollow">RubyZip does not create proper docx archives</a>.</p> <p>Edit: here is the code:</p> <pre><code>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 =&gt; 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 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload