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.

How do I achieve this? Please help! Thanks!

On Aug 27, 7:47 am, Frederick Cheung <[email protected]>
wrote:
> On Aug 27, 8:35 am, John Doe <[email protected]> wrote:
>
>
>
> > In my projects controller, I am trying to do this:
>
> > @projects = Project.find(:all, :include => [:books])
>
> > 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.
>
> Fred
>
>
>
>
>
>
>
> > projects: [
> >   {
> >     ..,
> >     books: [
> >         {
> >           ..
> >         },
> >         {
> >           ..
> >         }
> >     ]
> >   }
> > ]
>
> > But that does't work. How can I achieve this?
>
> > Thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to