lib/jsonapionify/api/server.rb in jsonapionify-0.9.0 vs lib/jsonapionify/api/server.rb in jsonapionify-0.9.1
- old
+ new
@@ -21,20 +21,24 @@
def initialize(env, api)
@api = api
@request = Request.new(env)
request.path_info.split('/').tap(&:shift).tap do |parts|
+ parts[-1] = File.basename(parts[-1], File.extname(parts[-1])) if parts[-1]
@resource, @id, @relationship, @relationship_name, *@more = parts
- request.env['jsonapionify.resource_name'] = @resource if @resource
- request.env['jsonapionify.resource'] = resource if @resource
- request.env['jsonapionify.id'] = @id if @id
end
end
def response
+ request.env['jsonapionify.resource_name'] = @resource if @resource
+ request.env['jsonapionify.resource'] = resource if @resource
+ request.env['jsonapionify.id'] = @id if @id
@resource ? resource.process(request) : api_index
rescue Errors::ResourceNotFound
- api.http_error(:not_found, request)
+ resource = @resource
+ api.http_error(:not_found, request) do
+ detail "Resource not found: #{resource}"
+ end
end
private
def api_index