2011-09-15 21:41:26 +00:00
|
|
|
class ThingsController < ApplicationController
|
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
def show
|
2012-01-14 22:31:01 +00:00
|
|
|
@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)
|
2011-09-15 21:41:26 +00:00
|
|
|
else
|
2014-04-01 08:15:29 +00:00
|
|
|
respond_with @things
|
2011-09-15 21:41:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@thing = Thing.find(params[:id])
|
2012-11-15 17:34:19 +00:00
|
|
|
if @thing.update_attributes(thing_params)
|
2011-09-15 21:41:26 +00:00
|
|
|
respond_with @thing
|
|
|
|
else
|
2014-03-25 09:47:44 +00:00
|
|
|
render(json: {errors: @thing.errors}, status: 500)
|
2011-09-15 21:41:26 +00:00
|
|
|
end
|
|
|
|
end
|
2012-11-15 17:34:19 +00:00
|
|
|
|
2014-04-01 08:15:29 +00:00
|
|
|
private
|
2012-11-15 17:34:19 +00:00
|
|
|
|
|
|
|
def thing_params
|
|
|
|
params.require(:thing).permit(:name, :user_id)
|
|
|
|
end
|
2011-09-15 21:41:26 +00:00
|
|
|
end
|