【发布时间】:2017-02-16 15:26:38
【问题描述】:
我在 Rails 4 中使用 prawn gem
我有以下宝石:
gem 'prawn'
gem 'prawn-table'
gem 'prawn-qrcode'
我收到以下错误:
Prawn::Errors::UnrecognizedTableContent
当我这样做时:
require 'prawn/qrcode'
class ReportPdf < Prawn::Document
def initialize(organizations)
super()
@organizations = organizations
table_content
end
def table_content
table organization_rows do
row(0).font_style = :bold
self.header = true
self.row_colors = ['DDDDDD', 'FFFFFF']
self.column_widths = [40, 300, 200]
end
end
def organization_rows
[['#', 'Name', 'id']] +
@organizations.map do |organization|
[render_qr_code(RQRCode::QRCode.new(organization.id.to_s)), organization.name, organization.id]
end
end
end
谁能提供一个在表格的每一行中添加二维码的示例?
更新:
我将我的表格代码更改为以下(我在二维码中添加了.to_s:
def organization_rows
[['#', 'Name', 'id']] +
@organizations.map do |organization|
[render_qr_code(RQRCode::QRCode.new(organization.id.to_s)).to_s,
organization.name,
organization.id]
end
end
现在,我得到以下 pdf。见截图。如何在表格单元格中获取这些二维码?
【问题讨论】:
-
我从不使用prawn-qrcode,但他们在github.com/jabbrwcky/prawn-qrcode/tree/master/examples有一些例子,可能对你有用
-
是的,我已阅读文档。不过谢谢。
标签: ruby-on-rails prawn