Wicked_pdf too few arguments in demo

喜你入骨 提交于 2019-12-24 12:33:21

问题


I'm trying to get wicked_pdf working for the first time as a project in learning RoR, but i've run into an issue.

When I try to run any of the demo's I've read around the place using the format.pdf do command, I get the error "Too few arguments" with highlighting on the format.pdf do line.

This is the code:

  def show
    format.pdf do
      render :pdf => "file_name", :template => 'certificates/show.pdf.erb'
    end
  end

What am I missing?


回答1:


try this.. I had same problem.

def show
    #format.pdf do
      render :pdf => "file_name", :template => 'certificates/show.pdf.erb'
    #end
  end

I believe you have gems 'wkhtmltopdf-binary' and 'wicked_pdf' installed




回答2:


enclose

 format.pdf do
      render :pdf => "file_name", :template => 'certificates/show.pdf.erb'
    end

in a respond_to block, something like:

respond_to do |format|
   format.pdf do
      render :pdf => "file_name", :template => 'certificates/show.pdf.erb'
    end
end



回答3:


Quick way

Install the following gems

gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'

Use which wkhtmltopdf and identify the path

Create a symbolic link

ln -s path_from_which /usr/local/bin/wkhtmltopdf

Edit/Create wicked initializers

WickedPdf.config = {
  #:wkhtmltopdf => '/usr/local/bin/wkhtmltopdf',
  #:layout => "pdf.html",
  :exe_path => '/usr/local/bin/wkhtmltopdf'
}

In your controller find your action and

def show
  render pdf: "file_name"   # Excluding ".pdf" extension.
end



回答4:


Add :layout

render :pdf => "notifications",
        :layout => 'layouts/pdf/layout.html.erb',
        :template => 'notification_compulsories/show.pdf.erb'



回答5:


I had this issue and the solution for me was to include the html format in the respond_to block. This

respond_to do |format|
  format.pdf  { render pdf: "ticket_report" }
end

became this:

respond_to do |format|
  format.html { render :index }
  format.pdf  { render pdf: "report" }
end



回答6:


I had this problem. You can add a defaults hash to the route and specify the format.

get "/pdf_name.pdf" => "your_controller#action", as: :pdf_route, defaults: { format: :pdf }



来源:https://stackoverflow.com/questions/22877724/wicked-pdf-too-few-arguments-in-demo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!