未定义的局部变量或方法`pdf'对于

时间:2016-08-10 09:07:19

标签: ruby-on-rails ruby pdf-generation prawn prawnto

我尝试使用 Prawn 在rails中生成 pdf 文件! 正如here

所解释的那样

完全一样! 但我有这个错误:

undefined local variable or method `pdf' for #<#<Class:0x005619ea6fecd0>:0x005619e9f54660>

这条线!

pdf.text "Hello World!"

似乎理解&lt; pdf。&#39; 你能帮帮我吗? 在此先感谢:)

1 个答案:

答案 0 :(得分:0)

我自己找到答案让我们一起回顾。 这是我的控制器

def show
  @resume = current_user.resume
end

这是我的观点(按钮):

<%= link_to t(:ExporttoPDF) , resume_path( :format => "pdf"),class:"btn btn-danger btn-lg"%>

我将所有这些宝石添加到我的宝石文件中!

 gem 'prawn_rails'
 gem 'prawn'
 gem 'prawn-table', '~> 0.1.0'
 gem 'prawnto'

这是我在简历视图中的 show.pdf.prawn 文件!

pdf.text "Hello World!"

它的功效就像一个魅力! 注意:我认为我的控制器存在一些问题:)