+ before_filter :find_object_by_uuid, :except => :index
+
+ unless Rails.application.config.consider_all_requests_local
+ rescue_from Exception,
+ :with => :render_error
+ rescue_from ActiveRecord::RecordNotFound,
+ :with => :render_not_found
+ rescue_from ActionController::RoutingError,
+ :with => :render_not_found
+ rescue_from ActionController::UnknownController,
+ :with => :render_not_found
+ rescue_from ActionController::UnknownAction,
+ :with => :render_not_found
+ end
+
+ def render_error(e)
+ if @object and @object.errors and @object.errors.full_messages
+ errors = @object.errors.full_messages
+ else
+ errors = [e.inspect]
+ end
+ render json: { errors: errors }, status: 422
+ end
+
+ def render_not_found
+ render json: { errors: ["Path not found"] }, status: 401
+ end
+
+ def index
+ @objects ||= model_class.all
+ render_list
+ end
+
+ def show
+ render json: @object
+ end
+
+ def create
+ @attrs = params[resource_name]
+ if @attrs.nil?
+ raise "no #{resource_name} (or #{resource_name.camelcase(:lower)}) provided with request #{params.inspect}"
+ end
+ if @attrs.class == String
+ @attrs = uncamelcase_hash_keys(JSON.parse @attrs)
+ end
+ @object = model_class.new @attrs
+ @object.save
+ show
+ end
+
+ def update
+ @attrs = params[resource_name]
+ if @attrs.is_a? String
+ @attrs = uncamelcase_hash_keys(JSON.parse @attrs)
+ end
+ @object.update_attributes @attrs
+ show
+ end