简体   繁体   English

努力实现对虾栏宝石

[英]struggling to implement prawn-rails gem

I am currently trying this prawn-rails gem. 我目前正在尝试使用此prawn-rails宝石。 Please note this is not the famous gem 'prawn' . 请注意,这不是著名的gem 'prawn'

Following prawn-rails instructions per se (correctly I hope!), so far, I have: 遵循prawn-rails说明本身(我希望正确!),到目前为止,我有:

In Users' Controller 在用户控制器中

  def test 
    @users = User.all
  end

In Users' Index View 在用户索引视图中

<%= link_to "Download PDF", users_test_path(:format=>:pdf) %>

In views/users/test.pdf.prawn 在views / users / test.pdf.prawn中

prawn_document do |pdf|
  @users.each {|u| pdf.text u }
end

In routes 在路线上

get "users/test"

Yet, whenever I attempt to click on the Download PDF link in the user's index, this is what I get: 但是,每当我尝试单击用户索引中的“ Download PDF链接时,都会得到以下信息:

NoMethodError at /users/test.pdf

undefined method `encode' for #<User:0x007fc6fadb0380>
Did you mean?  encode_with

Any ideas why? 有什么想法吗?

Changed my views/users/test.pdf.prawn to this: 将我的观点/用户/test.pdf.prawn更改为:

prawn_document do |pdf|

    pdf.font_size 25 
    pdf.text 'List of Users', :style => :bold

  @users.each do |u|  
    pdf.font_size 16
    pdf.text u.first_name + " " + u.last_name
  end

end

And then it showed the results 然后显示结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM