Allow user to pass in number of fire hydrants

This commit is contained in:
Erik Michaels-Ober 2011-05-22 06:16:12 -07:00
parent c1161e7852
commit 97c3eb6f2c
4 changed files with 5 additions and 3 deletions

View File

@ -19,7 +19,7 @@ class HydrantsController < ApplicationController
end
def list
@hydrants = Hydrant.find_closest(params[:lat], params[:lng])
@hydrants = Hydrant.find_closest(params[:lat], params[:lng], params[:limit] || 50)
unless @hydrants.blank?
respond_with @hydrants
else

View File

@ -8,7 +8,7 @@ class Hydrant < ActiveRecord::Base
ORDER BY distance
LIMIT ?
SQL
Hydrant.find_by_sql([query, lat, lng, lat, limit])
Hydrant.find_by_sql([query, lat.to_f, lng.to_f, lat.to_f, limit.to_i])
end
def adopted?

View File

@ -8,6 +8,7 @@
= select_tag "city_state", '<option value="Boston, MA" selected="selected">Boston, MA</option>'.html_safe, :tabindex => 10
= label_tag "address", "Address", :id => "address_label"
= text_field_tag "address", params[:address], :tabindex => 11
= hidden_field_tag "limit", params[:limit] || 50
= submit_tag "Find fire hydrants", :tabindex => 12
#logos
= image_tag "logos/cfa.png", :alt => "Code for America", :title => "Code for America"

View File

@ -72,7 +72,8 @@ $(function() {
'utf8': '✓',
'authenticity_token': $('#address_form input[name="authenticity_token"]').val(),
'lat': lat,
'lng': lng
'lng': lng,
'limit': $('#address_form input[name="limit"]').val()
},
success: function(data) {
if(data.errors) {