【问题标题】:Can't generate wicked pdf in rails 4无法在rails 4中生成邪恶的pdf
【发布时间】:2014-07-31 22:00:56
【问题描述】:

大家好,我正在尝试在 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"

我正在尝试导出视图

这里是demo and code

有人可以帮我配置wicked_pdf吗?

【问题讨论】:

  • 你需要在你的Gemfile中添加gem 'wicked_pdf'gem 'wkhtmltopdf-binary',然后在终端中执行bundle install

标签: ruby-on-rails ruby-on-rails-4 wicked-pdf wicked-gem


【解决方案1】:

一些事情

首先,您需要将 gem 'wicked_pdf'gem 'wkhtmltopdf-binary' 放入您的 Gemfile 并运行 bundle install

第二, 根据文档而不是

rails g wicked pdf

你应该进入

rails g wicked_pdf

【讨论】:

  • 您是否编辑过您的 Gemfile?因为您发布的演示,您的 Gemfile 没有 wicked_pdf。这就是问题的根源。
【解决方案2】:

最近被同样的问题惊呆了

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 文档几乎没有介绍这一点

【讨论】:

    【解决方案3】:

    你肯定需要指定一些路径!所以在你的 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
    

    【讨论】:

      【解决方案4】:

      在 Gemfile 中试试这个

      gem 'wicked_pdf'
      

      然后在终端中

      bundle
      

      然后在终端中

      rails g wicked_pdf
      

      然后你添加 Gemfile

      gem 'wkhtmltopdf-binary'
      

      然后在终端中点击 bundle ,所有这些都应该适用于 rails 5。我打赌也适用于 rails 4

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-16
        • 1970-01-01
        • 1970-01-01
        • 2014-06-10
        • 1970-01-01
        相关资源
        最近更新 更多