Prawn:如何从表头的迭代中的表进行迭代?

时间:2019-04-16 08:29:28

标签: ruby-on-rails ruby pdf iteration prawn

我将3个@course ID传递给course.pdf。 然后Prawn生成3页的PDF-1个课程的PR页。

问题:当前,它在所有3页中的所有3门课程中打印所有@participant。

它应该仅在表中打印当前课程的@参与者。

我花了几个小时尝试不同的方法,在Facebook小组中询问,并在Stackoverflow + Google上搜索了解决方案。

<?xml version="1.0" encoding="UTF-8"?>
<programs xmlns="http://someUrl.nl/schema/enterprise/program">
<program xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://someUrl.nl/schema/enterprise/program http://someUrl.nl/schema/enterprise/program.xsd">
<customizableOnRequest>true</customizableOnRequest>
<editor>webmaster@url</editor>
<expires>2019-04-21</expires>
<format>Edu-dex 1.0</format>
<generator>www.Url.com</generator>
<includeInCatalog>Catalogs</includeInCatalog>
<inPublication>true</inPublication>
<lastEdited>2019-04-12T20:03:09Z</lastEdited>
<programAdmission>
    <applicationOpen>true</applicationOpen>
    <applicationType>individual</applicationType>
    <maxNumberOfParticipants>12</maxNumberOfParticipants>
    <minNumberOfParticipants>8</minNumberOfParticipants>
    <paymentDue>up-front</paymentDue>
    <requiredLevel>academic bachelor</requiredLevel>
    <startDateDetermination>fixed starting date</startDateDetermination>
</programAdmission>
<programCurriculum>
    <instructionMode>training</instructionMode>
    <teacher>
        <id>{D83FFC12-0863-44A6-BDBB-ED618627F09D}</id>
        <name>SomeName</name>
        <summary xml:lang="nl">
        Long text of the summary. Not needed.
        </summary>
    </teacher>
    <studyLoad period="hour">26</studyLoad>
</programCurriculum>
<programDescriptions>
    <programName xml:lang="nl">Program Course Name</programName>
    <programSummaryText xml:lang="nl">short Program Course Name summary</programSummaryText>
    <programSummaryHtml xml:lang="nl">short Program Course Name summary in HTML format</programSummaryHtml>
    <programDescriptionText xml:lang="nl">This part is needed from the XML.
        Big program description text. This part is needed to parse from the XML file.
    </programDescriptionText>
    <programDescriptionHtml xml:lang="nl">Not needed;
        Not needed as well;
    </programDescriptionHtml>
    <subjectText>
        <subject>curriculum</subject>
        <header1 xml:lang="nl">Beschrijving</header1>
        <descriptionHtml xml:lang="nl">Yet another HTML desscription;
            Not necessarily needed;</descriptionHtml>
        </subjectText>
    <searchword xml:lang="nl">search word</searchword>
    <webLink xml:lang="nl">website-url</webLink>
</programDescriptions>
<programSchedule>
    <programRun>
        <id>PR-019514</id>
        <status>application opened</status>
        <startDate isFinal="true">2019-06-26</startDate>
        <endDate isFinal="true">2020-02-11</endDate>
    </programRun>
</programSchedule>
</program>
</programs>

1 个答案:

答案 0 :(得分:0)

参加考试是否包含课程参考?如果是这样,可能是这样的

def deltakere_rows(course)
  [["ID", "Name"]] +
    @participations.select do |p|
      p.course_id == course.id
    end.map do |p|
      [p.participant.id, p.participant.full_name]
    end
end

然后将课程传递给deltakere_rows

table deltakere_rows(course) do
  self.header = true
end

这可能是我们拥有的信息的想法