【发布时间】:2012-03-24 15:18:24
【问题描述】:
所以我有一个 Rails 应用程序,在用户提交后,它应该根据用户输入生成某种 .tex 文件,将其编译成 pdf,然后交付 pdf。通过消除过程,我非常肯定除了一条线外一切正常;调用 pdflatex 的那个。
以下是重要的 sn-p 代码: (如果重要,它位于生成操作下的 Questions 控制器中,该操作在表单发送相关信息后调用。虽然这可能不是最好的方法,但我很确定它不是错误的原因)
texHeader = 'app\assets\tex\QuestionsFront.txt'
texOut = 'app\assets\tex\Questions.tex'
#copy latex header to new file
FileUtils.cp(texHeader, texOut)
File.open(texOut, 'a+') do |fout|
fout.write("\n")
# a loop writes some more code to fout (its quite lengthy)
fout.write("\\end{enumerate}\n")
fout.write("\\end{document}")
#The problem line:
puts `pdflatex app/assets/tex/Questions.tex --output-directory=app/assets/tex`
end
filename = 'Questions.pdf'
filelocation = "app\\assets\\tex\\" + filename
File.open(filelocation, 'r') do |file|
send_file file, :filename => filename, :type => "application/pdf", :disposition => "attachment"
end
end
这是我的推理:它正确地生成 .tex 文件,并且给定一个预先创建的 Questions.pdf 文件,它可以很好地发送它。当 puts 中的命令被复制到终端时,它会顺利运行(文件以 \nonstopmode 开头,所以不用担心小错误)。但是由于某种原因,当我运行上面的脚本时,甚至没有创建一个错误的日志文件。
我忽略了什么?有任何想法吗?有什么方法可以查看 puts 行正在创建什么输出?
提前非常感谢!
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 io pdflatex