Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails:如何使用Heroku上的SystemZip从xml模板生成docx?_Ruby On Rails_Ruby_Heroku_Zip_Docx - Fatal编程技术网

Ruby on rails Rails:如何使用Heroku上的SystemZip从xml模板生成docx?

Ruby on rails Rails:如何使用Heroku上的SystemZip从xml模板生成docx?,ruby-on-rails,ruby,heroku,zip,docx,Ruby On Rails,Ruby,Heroku,Zip,Docx,我在本地工作,将模板文件存储在{Rails.root}/tmp中,使用系统“cdtmp/template;zip-r../{@filename}*”压缩文件,将.docx(zip存档)发送到S3,然后发送到浏览器。问题是Heroku找不到这些文件。在创建xml文件之前,我正在从另一个位置复制模板目录(system“cp-R support/ser_template tmp/”)。我理解Heroku的,但我不能让{Process.pid}乱丢文件名(Word要求xml文件名为document.xm

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

我是否可以在Amazon上存储模板文件,并且仍然使用Heroku的system zip实用程序

编辑:以下是代码:

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}\u docx/something\u nice/
?将所需内容复制(或符号链接)到:

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

然后你有:

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

有一个很好的内部结构,不包括PID。

我仍然得到
Errno::enoint
没有这样的文件或目录-/app/tmp/1\u ser/word/document.xml
Heroku。我现在已经在3个不同的堆栈(竹1.8.7、竹1.9.2和雪松)上进行了尝试。除了Bambol 1.9.2之外,我在所有版本上都没有得到
这样的文件或目录
,我的
权限被拒绝了-/app/tmp/1_ser/word/document.xml
@Reed:您是在一个进程中创建目录,但试图在另一个进程中访问它吗?投诉的是复制还是压缩?我在一个过程中创建和压缩文件(用户请求Word导出,并使用
render_to_string
从视图生成xml模板)。我在这一行发现了错误:
xml=File.open(xml_path,'w')
@Reed:您是否检查了您创建的目录的权限,或者您的umask在Heroku上是什么?
#{Rails.root}/tmp/#{Process.pid}_docx/x.zip