I have 3 tables: pupils: id, name, born_date, sex courses: id, course_name, description pupilXcourse: pupil_id, course_id Today I run a Pupil.find(:all) and send a json response to the browser, who shows a table of pupils and its attributes. I want to include in this listing on the browser a field showing what courses each pupil got. I don`t know the fast/easy method to achieve this. Maybe a custom, more complex, select statment, or a additional select with additional json request. If you have hints or examples, it you be very welcome. Thank you! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Nov 20, 8:02 am, Tom Lobato <tomlob...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have 3 tables: > pupils: id, name, born_date, sex > courses: id, course_name, description > pupilXcourse: pupil_id, course_id > > Today I run a Pupil.find(:all) and send a json response to the > browser, who shows a table of pupils and its attributes. > I want to include in this listing on the browser a field showing what > courses each pupil got.If you''re just using Rails'' to_json and you''ve got the appropriate associations then you can just do pupils.to_json :include => :courses Fred> I don`t know the fast/easy method to achieve this. Maybe a custom, > more complex, select statment, or a additional select with additional > json request. > > If you have hints or examples, it you be very welcome. > > Thank you!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
How will this ":include" change the json response? Since there is a list being selected, I need to parse it in the client side. I`m not using simple to_json, but to_ext_json (provided by the plugin: http://inside.glnetworks.de/2008/01/18/announcing-ext-scaffold-generator-plugin-for-rails/), but I think the "include" won`t change. On Nov 20, 6:49 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 20, 8:02 am, Tom Lobato <tomlob...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have 3 tables: > > pupils: id, name, born_date, sex > > courses: id, course_name, description > > pupilXcourse: pupil_id, course_id > > > Today I run a Pupil.find(:all) and send a json response to the > > browser, who shows a table of pupils and its attributes. > > I want to include in this listing on the browser a field showing what > > courses each pupil got. > > If you''re just using Rails'' to_json and you''ve got the appropriate > associations then you can just do pupils.to_json :include => :courses > > Fred > > > I don`t know the fast/easy method to achieve this. Maybe a custom, > > more complex, select statment, or a additional select with additional > > json request. > > > If you have hints or examples, it you be very welcome. > > > Thank you!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 20 Nov 2008, at 13:29, Tom Lobato wrote:> > > How will this ":include" change the json response? Since there is a > > list being selected, I need to parse it in the client side. > I`m not using simple to_json, but to_ext_json (provided by the plugin: > http://inside.glnetworks.de/2008/01/18/announcing-ext-scaffold-generator-plugin-for-rails/) > , > but I think the "include" won`t change. >http://api.rubyonrails.com/classes/ActiveRecord/Serialization.html#M001417> On Nov 20, 6:49 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On Nov 20, 8:02 am, Tom Lobato <tomlob...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> I have 3 tables: >>> pupils: id, name, born_date, sex >>> courses: id, course_name, description >>> pupilXcourse: pupil_id, course_id >> >>> Today I run a Pupil.find(:all) and send a json response to the >>> browser, who shows a table of pupils and its attributes. >>> I want to include in this listing on the browser a field showing >>> what >>> courses each pupil got. >> >> If you''re just using Rails'' to_json and you''ve got the appropriate >> associations then you can just do pupils.to_json :include => :courses >> >> Fred >> >>> I don`t know the fast/easy method to achieve this. Maybe a custom, >>> more complex, select statment, or a additional select with >>> additional >>> json request. >> >>> If you have hints or examples, it you be very welcome. >> >>> Thank you! > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <title></title> </head> <body bgcolor="#ffffff" text="#000000"> Frederick Cheung escreveu:<br> <blockquote cite="mid:15214C8C-B92F-41D5-855D-AC11F27DFD32-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" type="cite"> <pre wrap="">On 20 Nov 2008, at 13:29, Tom Lobato wrote: </pre> <blockquote type="cite"> <pre wrap=""> How will this ":include" change the json response? Since there is a list being selected, I need to parse it in the client side. I`m not using simple to_json, but to_ext_json (provided by the plugin: <a class="moz-txt-link-freetext" href="http://inside.glnetworks.de/2008/01/18/announcing-ext-scaffold-generator-plugin-for-rails/">http://inside.glnetworks.de/2008/01/18/announcing-ext-scaffold-generator-plugin-for-rails/</a>) , but I think the "include" won`t change. </pre> </blockquote> <pre wrap=""><!----><a class="moz-txt-link-freetext" href="http://api.rubyonrails.com/classes/ActiveRecord/Serialization.html#M001417">http://api.rubyonrails.com/classes/ActiveRecord/Serialization.html#M001417</a> </pre> </blockquote> great!<br> Sorry for didn`t look at this doc before, but in really it was not <br> clear even the fact that :include is a to_json option.<br> The things was confuse for me.<br> Now it`s clear.<br> <br> Thank you, Cheung!<br> <br> <br> Tom Lobato<br> <br> <br> --~--~---------~--~----~------------~-------~--~----~<br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. <br> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en<br> -~----------~----~----~----~------~----~------~--~---<br> </body> </html> <br>