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)
|
2011-09-15 21:41:26 +00:00
|
|
|
unless @things.blank?
|
|
|
|
respond_with @things
|
|
|
|
else
|
2012-06-18 17:49:28 +00:00
|
|
|
render(json: {errors: {address: [t("errors.not_found", thing: t("defaults.thing"))]}}, status: 404)
|
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
|
2012-06-18 17:49:28 +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
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def thing_params
|
|
|
|
params.require(:thing).permit(:name, :user_id)
|
|
|
|
end
|
2011-09-15 21:41:26 +00:00
|
|
|
end
|