adopt-a-hydrant/app/controllers/hydrants_controller.rb

22 lines
575 B
Ruby
Raw Normal View History

2011-03-08 08:44:27 +00:00
class HydrantsController < ApplicationController
2011-05-31 11:12:02 +00:00
respond_to :json
2011-05-06 02:38:25 +00:00
2011-03-27 18:45:58 +00:00
def show
@hydrants = Hydrant.find_closest(params[:lat], params[:lng], params[:limit] || 50)
unless @hydrants.blank?
2011-05-06 02:38:25 +00:00
respond_with @hydrants
else
2011-05-16 06:32:46 +00:00
render(:json => {"errors" => {"address" => ["Could not find hydrants."]}}, :status => 404)
end
end
2011-03-08 08:44:27 +00:00
def update
@hydrant = Hydrant.find(params[:id])
if @hydrant.update_attributes(params[:hydrant])
2011-05-06 02:38:25 +00:00
respond_with @hydrant
2011-03-08 08:44:27 +00:00
else
2011-05-16 06:32:46 +00:00
render(:json => {"errors" => @hydrant.errors}, :status => 500)
2011-03-08 08:44:27 +00:00
end
end
end