Welcome to the Treehouse Community
Looking to learn something new?
Jeff Carlson2,178 Points
I have been dabbling in rails for 6 months + and just took the rails course here. I have most of the first site done. I am stuck trying to do something a little more UI heavy than anything I have seen.
I have a collection_select control. I use this to select a student. When I select a student I need the student information to change, and then in a separate fragment, I need the Grade and Class combinations to be shown for that student. Grade is what links Student to Class.
The issue is that I can capture the event from the collection_select control with js using $(this).find(":selected").text(); or $(this).find(":selected").val(); How do I: (1) Get the return of the js function back to the controller and (2) call a method on the controller to repaint the page, based on the newly selected Student. (Maybe 2 and 1 are the same thing really).
I have looked all over here for an example, all over Rails Screencasts and I see nothing. I would love it if someone from this community could help and if maybe guys at teamtreehouse.com could build an example of something like this to show me the proper ruby way of doing something like this.
Jason SeiferTreehouse Guest Teacher
Hey Jeff Carlson this is a great question! Once you get the selected value, you can use that to fire off an ajax request to the controller and update other UI on the page with that data. It's a bit complicated but check out jQuery's .ajax method as well as some of the later lessons on where we use ajax.