Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] rendering an object as json calls JSON.encode(object) instead of object.to_json

#5655

Given I have the following code:

class User < ActiveRecord::Base
def to_json(options = {})

super options.merge :include => :parent

end end

class UsersController < ActionController::Base
def show

render :json => User.find(params[:id])

end end

the expected behaviour would be to render the user as json including the parent. This is not the current behaviour because today the user is rendered calling ActiveSupport::JSON.encode(user, options) instead of user.to_json(options) . I changed the implementation and nothing did break, so I think there is nothing wrong of changing this. I did also talk with a lot of people and all think calling to_json should be the default behaviour.

A patch is attached.

Reported by Diego Carrion · September 18th, 2010 @ 03:15 PM

State: resolved
Milestone: none
Assigned to: José Valim José Valim
Importance: none