简体   繁体   中英

wicked_pdf with rails 3.1 and ruby 1.9.2

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,

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 :)

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"?

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

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>  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM