Scott Parks
2007-Aug-15 20:00 UTC
Geodata SQL statements with multiple results in the controller
Hi Everyone- In my project I need to take a zip code and get all the schools within the selected mile radius of that zip code. In addition I will need to check to see if the user selected any other items to add to the search. My problem is the geo code will return multiple results and I need to get that result into the final sql string. The flow is this: Get the zip code and mile radius the user submitted - then run a query and get all schools within that mile radius of the user''s zip code. Take the results of that query and create a new query with the other options. The problem is the geo query returns multiple results and I need to access that array in the controller - is this possible by creating a class in the model? How would I access that array in the controller to prepare it for the second sql statement? 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 -~----------~----~----~----~------~----~------~--~---
James Stewart
2007-Aug-21 20:34 UTC
Re: Geodata SQL statements with multiple results in the controller
On 15 Aug 2007, at 21:00, Scott Parks wrote:> In my project I need to take a zip code and get all the schools > within the selected mile radius of that zip code. In addition I > will need to check to see if the user selected any other items to > add to the search. > > My problem is the geo code will return multiple results and I need > to get that result into the final sql string. > > The flow is this: > > Get the zip code and mile radius the user submitted - then run a > query and get all schools within that mile radius of the user''s zip > code. > > Take the results of that query and create a new query with the > other options. > > The problem is the geo query returns multiple results and I need to > access that array in the controller - is this possible by creating > a class in the model? How would I access that array in the > controller to prepare it for the second sql statement?Have you looked at any of the geo-location plugins that are kicking around? There''s a (slightly out of date) comparison chart at: http://foss4r.dyndns.org/trac/wiki/ComparingRailsGeoPlugins In particular, you might like to check out acts_as_locatable which will allow you to build queries of the form: School.find_within_radius(1, zip_code) I wrote some notes on extending that to accept other conditions. You can find my blog entry about it at: http://jystewart.net/process/2007/02/extending-acts_as_locateable/ James. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---