[英]Files in public directory in Rails - Errno::ENOENT (No such file or directory @ rb_sysopen
I'm currently working on a Rails 5.2 application using the combine pdf gem. 我目前正在使用Combine pdf gem开发Rails 5.2应用程序。 I'm trying to merge two PDF files but somehow I'm unable to load files from the
public
directory. 我正在尝试合并两个PDF文件,但无法以某种方式无法从
public
目录加载文件。
In the controller I have the following method: 在控制器中,我有以下方法:
def pdf_download
pdf = CombinePDF.new
pdf << CombinePDF.load("#{Rails.root}/public/pdfs/1.pdf")
pdf << CombinePDF.load("#{Rails.root}/public/pdfs/1.pdf")
pdf.save "combined.pdf"
send_data combined_file.to_pdf, filename: "combined.pdf", type: "application/pdf"
end
I have tried many posts on StackOverflow without success such as using Rails.root . 我已经尝试过许多关于StackOverflow的帖子,但没有成功,例如使用Rails.root 。 But I still get the same error:
但是我仍然遇到同样的错误:
Errno::ENOENT (No such file or directory @ rb_sysopen - app/public/pdfs/1.pdf):
Is there any additional configuration I have to do to load files from public
? 我是否需要做任何其他配置才能从
public
加载文件? and if these PDF shouldn't be in public
where should I store them? 如果这些PDF不应该
public
,我应该在哪里存储它们?
This fixed it for me: 这为我解决了:
def pdf_download
pdf = CombinePDF.new
pdf << CombinePDF.load(Rails.root.join("public", "pdfs/1.pdf").to_s)
pdf << CombinePDF.load(Rails.root.join("public", "pdfs/2.pdf").to_s)
# pdf.save "combined.pdf"
send_data pdf.to_pdf, filename: "combined.pdf", type: "application/pdf"
end
这为我解决了:
pdf << CombinePDF.load("./public/pdfs/1.pdf")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.