Skip to content

Paul Volpato: Rails to_json with multiple associations

July 5, 2010

Paul Volpato: Rails to_json with multiple associations

A small bit of undocumented goodness in the to_json method of ActiveRecord is how to do multiple associations with nested options.

For instance in a simple blog example. If you wanted to call to_json on your blog object and include all the posts and their comments you write:

blog.to_json({...
Advertisements

From → link

One Comment
  1. Joe Woodham permalink

    Hi Paul,

    im very keen on speaking with you about Ruby on Rails and a couple of opportunities i currently have, what is the best way of contacting you?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: