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

28 lines
632 B
Ruby
Raw Normal View History

class ThingsController < ApplicationController
respond_to :json
def show
@things = Thing.find_closest(params[:lat], params[:lng], params[:limit] || 10)
2014-04-01 08:15:29 +00:00
if @things.blank?
render(json: {errors: {address: [t('errors.not_found', thing: t('defaults.thing'))]}}, status: 404)
else
2014-04-01 08:15:29 +00:00
respond_with @things
end
end
def update
@thing = Thing.find(params[:id])
if @thing.update_attributes(thing_params)
respond_with @thing
else
2014-03-25 09:47:44 +00:00
render(json: {errors: @thing.errors}, status: 500)
end
end
2014-04-01 08:15:29 +00:00
private
def thing_params
params.require(:thing).permit(:name, :user_id)
end
end