Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

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

Add :layout

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

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

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 }

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top