seancribbs/webmachine-ruby — pull request #57 by petejohanson (2012-06-20 02:26:49+00:00)
Title: Initial work on accepting the content for a POST before retrieving the c...

...reate_path for the new Location header value.

Not sure if this change really is valid or not. Using this PR to get some clarity one way or another.

When using post_is_create? with a value of true, Decision::Flow will query the "create_path" *before* accepting the sent input type. For cases where processing the input creates a new resource, it's likely that the new create_path is not known until after saving some data to the database. With the current logic, you would need to put a dummy path for the response to "create_path", and then set the request.headers['Location'] yourself in the accept method.

Before:

class OrderResource
def post_is_create?
true
end

def create_path
"/orders/fake"
end

def content_types_accepted
['application/x-www-urlencoded', :accept_urlencoded]
end

def accept_urlencoded
order = Order.from_urlencoded(request.body)
order.save!
response.headers['Location'] = "/orders/#{order.id}"
end
end

With this change:

class OrderResource
def post_is_create?
true
end

def create_path
"/orders/#{@order.id}"
end

def content_types_accepted
['application/x-www-urlencoded', :accept_urlencoded]
end

def accept_urlencoded
@order = Order.from_urlencoded(request.body)
@order.save!
end
end

Am I misunderstanding the intended use of `create_path` and `content_types_accepted`?