wicked_pdf 与 Rails 3.1 和 ruby​​ 1.9.2

发布于 2025-01-01 05:31:13 字数 1005 浏览 0 评论 0原文

首先,我知道这种类型的帖子已经发布了,但我已经尝试了几乎所有的帖子,但无法得到结果,所以在这里我再次发布同样类型的问题。

其次,我这里没有资产管道问题,所以请忘记这一点。

现在让我解释一下我在做什么。我正在使用rails 3.1和ruby 1.9.2,我安装了wicked_pdf作为gem并安装了wkhtmltopdf,如wiki中所述,通过清除已安装的wkhtml并将新的wkhtml下载并提取到/usr/bin/wkhtmltopdf

我有一个初始化程序包含以下内容:

wicked_pdf.rb

WickedPdf.config = { :exe_path => '/usr/bin/wkhtmltopdf'}

在我看来,我有一个 link_to 方法,如下所示:

_filters.html.haml

= link_to 'show pdf', jobs_report_jobs_path(:format => :pdf), :method=>"post"

请注意,如果我删除:格式=> :pdf 选项在我的控制器中工作正常,

我正在执行以下操作:

report_jobs_controller.rb

respond_to do |format|
      format.html
      format.js
      format.pdf{
        render :pdf=>"jobs",
        :template => 'jobs.html.erb',
        :layout=>"jobs.html"
      }
end

请注意,我已单独尝试使用 format.pdf ,而无需任何选项。我尝试了“jobs.pdf.erb”,有或没有布局选项,以及我什至不记得的各种其他选项。我最终得到的只是 406 不可接受。

请指导我,因为我需要尽快实现此功能。

问候,

First of all i know this type of posts are already been made but i've tried almost all of them and i'm not been able to get the results so here i'm again posting the same kind of question.

Second of all i'm not having an asset pipeline issue here, so please forget about that.

Now let me explain what i'm doing. I'm using rails 3.1 and ruby 1.9.2, i installed wicked_pdf as a gem and installed wkhtmltopdf as mentioned in the wiki by purging the already installed wkhtml and downloading and extracting the new one to /usr/bin/wkhtmltopdf

I have an initializer that contains the following:

wicked_pdf.rb

WickedPdf.config = { :exe_path => '/usr/bin/wkhtmltopdf'}

In my view i have a link_to method as follows:

_filters.html.haml

= link_to 'show pdf', jobs_report_jobs_path(:format => :pdf), :method=>"post"

note if i remove the :format => :pdf option it works fine

in my controller i'm doing the following:

report_jobs_controller.rb

respond_to do |format|
      format.html
      format.js
      format.pdf{
        render :pdf=>"jobs",
        :template => 'jobs.html.erb',
        :layout=>"jobs.html"
      }
end

note that i have tried from format.pdf alone without any options. I tried "jobs.pdf.erb", with and without layout option, all sorts of other options i don't even remember. All i get is a 406 not acceptable in the end.

Please guide me coz i need to implement this feature asap.

Regards,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

悲欢浪云 2025-01-08 05:31:13

406 意味着请求无效(就该控制器操作可接受的内容而言)

我在 :format => 方面遇到了麻烦:pdf 之前。尝试 :format => 'pdf'

准系统的实现应该是:

format.pdf {
  render :pdf => 'jobs'
}

另外,link_to 真的应该是 :method => “邮政”?

406 means the request isn't valid (in regards to what is acceptable to that controller action)

I've had trouble with :format => :pdf before. Try :format => 'pdf'

The barebones implementation should just be:

format.pdf {
  render :pdf => 'jobs'
}

Also, is the link_to really supposed to be :method => "post"?

|煩躁 2025-01-08 05:31:13

我的应用程序控制器中有一个 before_filter ,它正在使用提到的身份验证格式检查每个请求,并且我在那里缺少 pdf 格式,因此一旦我将 :pdf 放入每个传入请求的格式列表中,它就可以正常工作。

i had a before_filter in my application controller that was checking every request with the mentioned format for authentication and i was missing pdf format there, so as soon as i put the :pdf in the list of formats for each incoming request it worked fine.

岛歌少女 2025-01-08 05:31:13

我也有同样的问题。我在ubuntu上工作。安装 wkhtmltopdf 后,我不再收到此错误。
在终端中运行以下命令:

$sudo apt-get install wkhtmltopdf

我希望这有帮助:)

I too had the same issue. I work on ubuntu. AFter I installed wkhtmltopdf, I am not getting this error any more.
in terminal run the command below:

$sudo apt-get install wkhtmltopdf

I hope this helps :)

Oo萌小芽oO 2025-01-08 05:31:13

我不太了解 wicked-pdf,但我曾经使用过 pdfkit,这就是我完成渲染部分的方式:

def pdf
  respond_to do |format|
      format.pdf { render :text => PDFKit.new( Pdf.find(params[:id]).content ).to_pdf }
    end
end

我希望代码足够清晰且自我解释性的。我的查看代码是:

<p><%= link_to "Download PDF", pdf_pdf_path(@pdf, :format => "pdf") %></p>  

I don't how much about wicked-pdf, but I once used pdfkit and this is how I did the rendering part:

def pdf
  respond_to do |format|
      format.pdf { render :text => PDFKit.new( Pdf.find(params[:id]).content ).to_pdf }
    end
end

I hope the code is clear enough and self-explanatory. My view code is:

<p><%= link_to "Download PDF", pdf_pdf_path(@pdf, :format => "pdf") %></p>  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文