Forum: Ruby on Rails Beyond the simple select

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6fd237f6f40f5afca32aca6ea633f58a?d=identicon&s=25 Tom Lobato (Guest)
on 2008-11-20 09:09
(Received via mailing list)
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!
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-20 09:49
(Received via mailing list)
On Nov 20, 8:02 am, Tom Lobato <tomlob...@gmail.com> 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
6fd237f6f40f5afca32aca6ea633f58a?d=identicon&s=25 Tom Lobato (Guest)
on 2008-11-20 14:30
(Received via mailing list)
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-...),
but I think the "include" won`t change.

On Nov 20, 6:49 am, Frederick Cheung <frederick.che...@gmail.com>
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-20 15:40
(Received via mailing list)
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-...)
> ,
> but I think the "include" won`t change.
>
http://api.rubyonrails.com/classes/ActiveRecord/Se...
6fd237f6f40f5afca32aca6ea633f58a?d=identicon&s=25 Tom Lobato (Guest)
on 2008-11-20 16:05
(Received via mailing list)
<!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@gmail.com"
 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-...)
,
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/Se...
  </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 &quot;Ruby on Rails: Talk&quot; group. <br> To post to this
group, send email to rubyonrails-talk@googlegroups.com <br> To
unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com <br> For more options,
visit this group at
http://groups.google.com/group/rubyonrails-talk?hl...
-~----------~----~----~----~------~----~------~--~---<br>
</body>
</html>
<br>
This topic is locked and can not be replied to.