My hope is to get a nested data structure back that looks something
like:
Well you what you get back is an array of projects where the book
objects have already been fetched fro the database
If you call to_json(:include => :books) then you should get output
pretty similar to what you've described.
But, I am sorry I did not get your explanation. Forgive me, I am very
new to Ruby and Rails. Could you please explain why it didn't work
before, and why it worked your way?
Also, in my controller, I'd like to call the parent controller's
method to format my json in a certain way...So instead of this:
respond_to do |format|
format.json { render :json => @projects.to_json(:include =>
[:apps]) }
end
I'd like to do something like this:
result = <nested data>
respond_to do |format|
format.json { render :json =>
some_method_in_parent_controller(result) }
end
So all my other controllers that subclass this parent application
controller can pass data to this parent controller's method and format
the data in a particular way.