From 97c3eb6f2c21e21c5363162b1e10f844ac51292f Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Sun, 22 May 2011 06:16:12 -0700 Subject: [PATCH] Allow user to pass in number of fire hydrants --- app/controllers/hydrants_controller.rb | 2 +- app/models/hydrant.rb | 2 +- app/views/main/index.html.haml | 1 + public/javascripts/application.js | 3 ++- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/hydrants_controller.rb b/app/controllers/hydrants_controller.rb index cfa529c..3a44826 100644 --- a/app/controllers/hydrants_controller.rb +++ b/app/controllers/hydrants_controller.rb @@ -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 diff --git a/app/models/hydrant.rb b/app/models/hydrant.rb index 2cd669e..70c08a5 100644 --- a/app/models/hydrant.rb +++ b/app/models/hydrant.rb @@ -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? diff --git a/app/views/main/index.html.haml b/app/views/main/index.html.haml index 3d74b27..507ae0c 100644 --- a/app/views/main/index.html.haml +++ b/app/views/main/index.html.haml @@ -8,6 +8,7 @@ = select_tag "city_state", ''.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" diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 6f7b8df..429984d 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -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) {