Skip to content

Instantly share code, notes, and snippets.

@danhixon
Created March 8, 2010 16:45
Show Gist options
  • Save danhixon/325338 to your computer and use it in GitHub Desktop.
Save danhixon/325338 to your computer and use it in GitHub Desktop.
# Building on the zips_near_zip procedure in this gist: http://gist.github.com/319908
# I added a named scope to my model which has an attribute of "service_address_id":
# call to sanitize_sql_array to avoid sql injection.
named_scope :near_zip, lambda { |zip, miles|
{ :joins=>sanitize_sql_array(["join addresses
on service_address_id=addresses.id
join zips_near_zip(?,?)
on zip_code = zip",zip, miles]) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment