【发布时间】:2026-01-27 14:10:01
【问题描述】:
我将 3 个@course ID 传递给 courses.pdf。 然后 Prawn 生成一个 3 页的 PDF - 一个课程 pr 页。
问题:目前它在所有 3 个页面中打印所有 3 个课程的所有 @participants。
它应该只在表格中打印当前课程的@participants。
我花了几个小时尝试不同的方法,在 Facebook 群组中询问并在 * + Google 上搜索解决方案。
class CoursesToPrintPdf < Prawn::Document
def initialize(courses, participations)
@courses = courses
@participations = participations
header
end
def header
@courses.order('day ASC').each do |course|
text_box("#{course.course_day_pdf}",
:align => :right)
text "#{course.round.round_name_simple}"
table deltakere_rows do
self.header = true
end
end
end
def deltakere_rows
[["ID", "Name"]] +
@participations.map do |p|
[p.participant.id, p.participant.full_name]
end
end
end
【问题讨论】:
标签: ruby-on-rails ruby pdf iteration prawn