2011-03-08 08:44:27 +00:00
|
|
|
class HydrantsController < ApplicationController
|
2011-05-06 02:38:25 +00:00
|
|
|
respond_to :json, :only => [:list, :update]
|
|
|
|
|
2011-03-27 18:45:58 +00:00
|
|
|
def show
|
|
|
|
@hydrant = Hydrant.find_by_id(params[:hydrant_id])
|
|
|
|
if @hydrant.adopted?
|
|
|
|
if user_signed_in? && current_user.id == @hydrant.user_id
|
2011-04-04 01:20:52 +00:00
|
|
|
render("users/thank_you", :layout => "info_window")
|
2011-03-27 18:45:58 +00:00
|
|
|
else
|
2011-04-04 01:20:52 +00:00
|
|
|
render("users/profile", :layout => "info_window")
|
2011-03-27 18:45:58 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
if user_signed_in?
|
2011-04-04 01:20:52 +00:00
|
|
|
render("adopt", :layout => "info_window")
|
2011-03-27 18:45:58 +00:00
|
|
|
else
|
2011-04-04 04:18:59 +00:00
|
|
|
render("sessions/new", :layout => "info_window")
|
2011-03-27 18:45:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-03-08 08:44:27 +00:00
|
|
|
|
2011-03-27 18:45:58 +00:00
|
|
|
def list
|
2011-03-17 20:53:05 +00:00
|
|
|
@hydrants = Hydrant.find_closest(params[:lat], params[:lng])
|
|
|
|
unless @hydrants.blank?
|
2011-05-06 02:38:25 +00:00
|
|
|
respond_with @hydrants
|
2011-03-17 20:53:05 +00:00
|
|
|
else
|
|
|
|
render(:json => {"errors" => {"address" => ["Could not find address."]}})
|
|
|
|
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
|
|
|
|
render(:json => {"errors" => @hydrant.errors})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|