简体   繁体   English

Rails的公共目录中的文件-Errno :: ENOENT(无此类文件或目录@ rb_sysopen

[英]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.

相关问题 Errno :: ENOENT - 没有这样的文件或目录@ rb_sysopen - Errno::ENOENT - No such file or directory @ rb_sysopen Errno::ENOENT 没有那个文件或目录@rb_sysopen - Errno::ENOENT No such file or directory @ rb_sysopen rails 4:Errno :: ENOENT(没有这样的文件或目录@ rb_sysopen - / assets / - rails 4: Errno::ENOENT (No such file or directory @ rb_sysopen - /assets/ 如何修复“Errno::ENOENT: No such file or directory @ rb_sysopen”? - How to fix “Errno::ENOENT: No such file or directory @ rb_sysopen”? Errno :: ENOENT(无此类文件或目录@ rb_sysopen-aws.yml) - Errno::ENOENT (No such file or directory @ rb_sysopen - aws.yml) Errno::ENOENT: 没有这样的文件或目录@rb_sysopen - /tmp/ - Errno::ENOENT: No such file or directory @ rb_sysopen - /tmp/ 带有 Rails API 的 Expo Image Picker 获取 Errno::ENOENT(没有这样的文件或目录 @ rb_sysopen - Expo Image Picker With Rails API gets Errno::ENOENT (No such file or directory @ rb_sysopen Errno::ENOENT: No such file or directory @ rb_sysopen webpacker:compile Issues for Rails depoloyment - Errno::ENOENT: No such file or directory @ rb_sysopen webpacker:compile Issues for Rails depoloyment 带有回形针的Errno :: ENOENT(无此类文件或目录@ rb_sysopen-aws.yml) - Errno::ENOENT (No such file or directory @ rb_sysopen - aws.yml) in rails with paperclip 看到“Getting Errno::ENOENT 'no such file or directory @ rb_sysopen'”时如何在 Rails 中获取正确的 Tempfile 文件路径 - How to get a proper filepath of Tempfile in Rails when seeing "Getting Errno::ENOENT ' no such file or directory @ rb_sysopen'"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM