How to get custom attributes on .to_json method? <p>For example, i've this model:</p> <pre><code>class User &lt; ActiveRecord::Base def foo bar end end </code></pre> <p>When i do this: &lt;%= User.all.to_json %></p> <p>I get this:</p> <p>[{"user":{"created_at":"2011-06-07T17:40:21-03:00","login":"abcd", "password":"1234","updated_at":"2011-06-07T18:10:04-03:00"}}]</p> <p>How can i get foo on this json too? Also, foo is an activerecord too..</p> <p>Thanks</p>