Topic: Rails/Google Maps/RouteBoxer javascript design

I am rather new to Rails and I have an idea of how I want a part of my mapping application to work. In my view, I make a directions request to google maps and it returns a DirectionsRoute object, with an attribute inside called overview_path.

After this happens, I would like to use the google utility class RouteBoxer to create a 10 mile wide corridor around the route. I then need to do a bounding box query against the LatLng points in my MySQL database and then make another directions request to google maps with one of these LatLng points as a waypoint in the route.

The way I understand it, I will need two bits of Javascript, one to get the A to B route, and the next to get the A to B to C route. I've done a lot of research to try to understand how this design would look but I can't really find what I am looking for.

Essentially, here are my questions: How and where do I use the first DirectionsRoute object to query my database? Can I use what is returned from a Javascript request in a RoR database query? Also, can I combine all of this into one Javascript without hopping out to query my database?

Thanks in advance for reading this and any input you can provide!