Rails 5 - 下载回形针附件

时间:2016-10-07 13:21:37

标签: ruby-on-rails paperclip

在我正在构建学习RoR的应用程序中,我想自动下载附加的pdf。随附Paperclip。然后使用pdfinfo获取pdf属性。

在我使用

附加的annotation.rb模型中
has_attached_file :file,
    styles: { large: "600x600>", medium: "500x500>", thumb: "150x150#" },
    default_url: "/images/:style/missing.png"

在我的AnnotationsController中

    require 'pdfinfo'
    pdfinfo = Pdfinfo.new('@annotation.file.path')
    page_count = pdfinfo.page_count

这会抛出错误

  

注释控制器中的Pdfinfo :: CommandFailed#pdf pdfinfo -f 0 -l -1   -enc UTF-8 @ annotation.file.path

此错误的含义是什么?如何才能读取文件?我学会了使用send_file下载,但没有成功。

1 个答案:

答案 0 :(得分:0)

您正在将文字字符串传递给新方法。您需要删除引号。

require 'pdfinfo'
pdfinfo = Pdfinfo.new(@annotation.file.path)
page_count = pdfinfo.page_count
相关问题