Reputation: 13402
I am trying to render multiple objects as JSON. This is my render call:
render :json => {:widget => @widget.to_json(:include => :foo),
:updated => Time.now.to_i}
I have to use to_json because of the include, and the addition updated so I know when the last call was made. The problem is that the to_json is rendered as a String instead of the object structure of the widget.
How do I get the full object structure of the widget and the updated information?
Upvotes: 3
Views: 2283
Reputation: 17790
Move the :include => :foo
into your Widget model.
class Widget < ActiveRecord::Base
def as_json(options = {})
super options.merge(:include => :foo)
end
end
Upvotes: 1