Joshua Kolden
2008-Jun-03 18:58 UTC
combining associated models into a single xml or json object
It is clear how to return a model with model.to_json or model.to_xml.
But how does one returned an object that with associations included?
I thought the following would work but it seems to only return the
base model.
folder = Folder.find_by_id(7, :include => [permissions])
respond_to do |f|
...
f.json { render :json => folder.to_json}
end
Thanks,
j
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Joshua Kolden
2008-Jun-03 19:49 UTC
Re: combining associated models into a single xml or json object
No sooner do I post than I realize my mistake.
(:include is the message to .to_json, not ''find'')
i.e.
f.json { render :json => folder.to_json(:include=> [permissions]) }
Thanks,
j
On Jun 3, 11:58 am, Joshua Kolden
<crackcreat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> It is clear how to return a model with model.to_json or model.to_xml.
> But how does one returned an object that with associations included?
> I thought the following would work but it seems to only return the
> base model.
>
> folder = Folder.find_by_id(7, :include => [permissions])
>
> respond_to do |f|
> ...
> f.json { render :json => folder.to_json}
> end
>
> Thanks,
> j
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---