使用Ruby Gem:prawn和扩展prawn-table来为prawn提供创建表格的功能。
使用prawn displayed here创建一个表的基础知识对于静态数据来说很简单:
# This works. Easy because it is static data
def prepare_for_print
pdf = Prawn::Document.new
pdf.font_size 11
pdf.font "Times-Roman"
pdf.table([ ["short", "short", "loooooooooooooooooooong "*30],
["short", "loooooooooooooooooooong "*15, "short"],
["loooooooooooooooooooong "*10, "short", "short"] ])
return pdf
end
很好。还不错。但是现在我想遍历一个活动的记录关系对象,但是我的尝试不起作用:
def prepare_for_print
pdf = Prawn::Document.new
pdf.font_size 11
pdf.font "Times-Roman"
calls_by_disability.each do |disability|
pdf.text "#{disability}", style: :bold, color: "001133"
pdf.table([ ["Call ID", "Date", "County", "Service Category", "Service", "Notes"],
disability.calls.each do |call|
["hello", "world", "foo", "bar", "bazz", "adsfsa"],
end
])
end
return pdf
end
问题在于迭代关联的调用:
disability.calls.each do |call|
["hello", "world", "foo", "bar", "bazz", "adsfsa"],
end
任何提示是赞赏。谢谢!
1条答案
按热度按时间dpiehjr41#