顧客一覧XMLを取得するアクションを作成

> ruby script/generate controller Accounting

app/controllers/accounting_controller.rbに以下のメソッドを追加

   def customer_list
      @customers = Customer.find(:all)
   end

app/views/accounting/customer_list.rxmlを以下のように作成

xml.instruct!
xml.customer_list_result do
    xml.invoice_customers do
        @customers.each do |customer|
            xml << customer.to_xml(:dasherize=>false,
               :skip_instruct=>true,
               :only=>[:id,:name,:address],
               :root=>"customer",
               :include => :customer_type) # belongs_toで指定したリレーションもXMLに
        end
    end
end

WEBrickサーバを起動し

> ruby script/server

次のようにブラウザに表示されたらOK
このXMLは保存して(customer_list.xmlとしておく)、次のiReportのテンプレートして使う。
最終的にはこのXMLの内容がPDFとして出力される。

<?xml version="1.0" encoding="UTF-8"?>
<customer_list_result>
  <invoice_customers>
<customer>
  <address>&#26481;&#20140;&#37117;&#28171;&#35895;&#21306;</address>
  <id type="integer">1</id>
  <name>&#26666;&#24335;&#20250;&#31038;&#12288;ABC</name>
  <customer_type>
    <id type="integer">1</id>
    <name>&#25903;&#25173;&#20808;</name>
  </customer_type>
</customer>
<customer>
  <address>&#26481;&#20140;&#37117;&#28171;&#35895;&#21306;</address>
  <id type="integer">2</id>
  <name>&#26666;&#24335;&#20250;&#31038;&#12288;CDE</name>
  <customer_type>
    <id type="integer">1</id>
    <name>&#25903;&#25173;&#20808;</name>
  </customer_type>
</customer>
<customer>
  <address>&#26481;&#20140;&#37117;&#28171;&#35895;&#21306;</address>
  <id type="integer">3</id>
  <name>&#26666;&#24335;&#20250;&#31038;&#12288;EFG</name>
  <customer_type>
    <id type="integer">3</id>
    <name>&#25903;&#25173;&#12539;&#35531;&#27714;</name>
  </customer_type>
</customer>
<customer>
  <address>&#26481;&#20140;&#37117;&#28171;&#35895;&#21306;</address>
  <id type="integer">4</id>
  <name>XYZ&#12288;&#26666;&#24335;&#20250;&#31038;</name>
  <customer_type>
    <id type="integer">2</id>
    <name>&#35531;&#27714;&#20808;</name>
  </customer_type>
</customer>
  </invoice_customers>
</customer_list_result>