I haven’t worked with render :xml, so I can’t help with b), though I
expect you’ll have to step back and create your xml document manually
using REXML or Builder instead of using the to_xml method. to_xml is
easy, but limited when you want to add information that is not
specifically part of the schema, but Builder is a cinch to use, too, so
you won’t have much ramp-up.
As to a)… assuming you have an order object in @order, then you can
get the count of line_items with:
Using Builder, you might include this in your xml document with
Which should result in something like:
Andrew C. wrote:
I am fairly new to Rails, and I am having difficulty in forgetting the
old way of developing and using the Rails way.
This is my question, using orders and line_items as an example.
An order has_many line_items
A line_item belongs to order
In my OrdersController I have
@orders = Orders.find(:all)
render :xml => @orders.to_xml()
What I want to achieve is to include a count of line_items per order,
and to include it as say total_line_items in the output.
I don’t know how to a.) get the count per order, b.) how to include in