大家好,我正在尝试在 rails 4 中使用 wicked pdf。
我关注这个页面 https://github.com/mileszs/wicked_pdf。
我做了:
gem install wicked pdf
然后我尝试了命令
rails g wicked_pdf
### And got "Could not find the generator"
我正在尝试导出视图
这是演示和代码
请有人可以帮我配置wicked_pdf?
大家好,我正在尝试在 rails 4 中使用 wicked pdf。
我关注这个页面 https://github.com/mileszs/wicked_pdf。
我做了:
gem install wicked pdf
然后我尝试了命令
rails g wicked_pdf
### And got "Could not find the generator"
我正在尝试导出视图
这是演示和代码
请有人可以帮我配置wicked_pdf?
一些东西
首先,您需要将其放入gem 'wicked_pdf'
并运行gem 'wkhtmltopdf-binary'
Gemfile
bundle install
其次,根据文档而不是
rails g wicked pdf
你应该进入
rails g wicked_pdf
最近被同样的问题惊呆了
rails generate wicked_pdf
Running via Spring preloader in process 28540
**Could not find generator 'wicked_pdf'**. Maybe you meant 'scaffold', 'helper' or 'mailer'
或者
NameError (uninitialized constant WickedPdf)
解决方法很简单。确保在 gem 安装后重新加载 Spring gem。
spring stop
由于 Spring 在 Rails 5.2 中是默认设置,因此 gem 文档中几乎没有涵盖这一时刻
你肯定需要指定一些路径!所以在你的 config/initializers/wicked_pdf.rb 请添加(或取消注释)这个:
WickedPdf.config = {
#:wkhtmltopdf => '/usr/local/bin/wkhtmltopdf',
#:layout => "pdf.html",
:exe_path => '/usr/local/bin/wkhtmltopdf'
}
也在你的控制器中:
respond_to do |format|
format.html
format.pdf do
render :pdf => "file_name.pdf",:template => "file Directory/file_name.html.erb"
end
end
在 Gemfile 中试试这个
gem 'wicked_pdf'
然后在终端
bundle
然后在终端
rails g wicked_pdf
然后你添加 Gemfile
gem 'wkhtmltopdf-binary'
然后在终端打 bundle ,所有的都应该为 rails 5 工作。我也打赌 rails 4