Hi everybody I'm trying to use wicked pdf in rails 4.

I follow this page https://github.com/mileszs/wicked_pdf.

I did:

gem install wicked pdf

Then I tried the command

rails g wicked_pdf
### And got "Could not find the generator"

I'm trying to export a view

Here is the demo and code

Please somebody can help me to configure wicked_pdf?

有帮助吗?

解决方案

A few things

First, you need to put this gem 'wicked_pdf' and gem 'wkhtmltopdf-binary' in your Gemfile and run bundle install

Second, According to the docs instead of

rails g wicked pdf

You should be entering

rails g wicked_pdf

其他提示

You surely need To specify some paths! So in your config/initializers/wicked_pdf.rb please add (Or Uncomment) this :

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

and also in your controller :

respond_to do |format|
    format.html
    format.pdf do
      render :pdf => "file_name.pdf",:template => "file Directory/file_name.html.erb"
    end
  end

Stunned with same issue recently

rails generate wicked_pdf Running via Spring preloader in process 28540 **Could not find generator 'wicked_pdf'**. Maybe you meant 'scaffold', 'helper' or 'mailer'

OR

NameError (uninitialized constant WickedPdf)

Resolution is simple. Make sure to reload Spring gem after gem installation.

spring stop

This moment is barely covered in gem docs since spring is default in Rails 5.2

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top