This project is archived and is in readonly mode.

#5073 ✓resolved
Mislav

AR::Relation can't be encoded to JSON

Reported by Mislav | July 8th, 2010 @ 09:26 PM | in 3.x

Although AR::Relation provides to_json, it still can't be encoded with ActiveSupport::JSON.encode because the latter detects a circular reference and errors out. So, this is not possible:

# controller action
render :json => relation

I fixed it by providing as_json method in AR::Relation.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages