render :json and associations

Is there any way to use the to_json includes when using
"render :json"?

I've got this:

format.json { render :json => { :order => @orders } }

But I'd also like to include the address (order.address) association.
The "to_json" method has all these options, but I don't see how I can
use that with render :json. If I tack on the to_json to @orders the
render :json escapes the whole thing. I'm using Ext JS on the client
side.

Thanks!

Is there any way to use the to_json includes when using
"render :json"?

I've got this:

format.json { render :json => { :order => @orders } }

render :json => @orders.to_json(...)

Fred

use eager loading on your @orders with :include option or use :select to
add attributes from address if you only need limited data from address
and performance is a concern.

Regards,

rp8

This works, but what if I want to add other json object that aren't in
orders? Ext JS needs a "count" param for it's client side
pagination. So I originally had this:

format.json { render :json => { :order => @orders, :count =>
@orders.size } }

I couldn't figure out how to use to_json in this situation.

I do have includes on the finder, but the associates are not sent with
the json output.

For now I wound up just building my own hash and returning that.

This works, but what if I want to add other json object that aren't in
orders? Ext JS needs a "count" param for it's client side
pagination. So I originally had this:

format.json { render :json => { :order => @orders, :count =>
@orders.size } }

format.json { render :json => { :order => @orders, :count =>
@orders.size }.to_json }

Fred