我的下载 zip 有问题。它工作正常,但 build 方法呈现 html 文件并提供如下链接:
<script src="/assets/impress.js?body=1" type="text/javascript"></script>
而我需要它是相对路径:
<script src="assets/impress.js?body=1" type="text/javascript"></script>
如何使用 ruby 删除链接开头的“/”。这是使用 zip gem 的代码部分。
def download
build
data = render_to_string :build
js_path = Rails.root.join("vendor", "assets", "javascripts")
zip = Zip::OutputStream.write_buffer do |out|
out.put_next_entry("index.html")
out.write(data)
out.put_next_entry("assets/impress.js")
out.write File.read js_path.join("impress.js")
end
zip.rewind
binary_zip = zip.sysread
send_data(binary_zip, {filename: "impress.zip"})
end