0
我使用axlsx宝石生成Excel电子表格。我试图将生成的电子表格发送到模型进行压缩。此方法将excel文件与其他一些文件进行压缩。的Rails:发送由axlsx视图生成的文件到模型
在我的模型的方法是这样的:
def zipper
tempfile = Tempfile.new
children = self.children_with_forms
Zip::OutputStream.open(tempfile) do |stream|
children.each do |child|
directory = "#{child.wide_reference[0,3]}/"
if child.model_name == "Position"
stream.put_next_entry("#{child.volume} #{child.title} TOC.xlsx")
stream.print IO.read(Rails.application.routes.url_helpers.toc_path(format: :xlsx, position_id: child.id))
end
stream.put_next_entry("#{directory}#{child.wide_reference}-#{child.short_name}-#{child.title.truncate(15, omission:'')}.docx")
stream.print IO.read(child.download_form.path)
end
end
tempfile
end
我有问题的部分是:
if child.model_name == "Position"
stream.put_next_entry("#{child.volume} #{child.title} TOC.xlsx")
stream.print IO.read(Rails.application.routes.url_helpers.toc_path(format: :xlsx, position_id: child.id))
end
我如何生成的文件将模型?
agustaf,你应该在这里发表您的最终解决方案,并标记您自己的答案是正确的。 – noel