This project is archived and is in readonly mode.
respond_with should exhibit common behaviour for "API" requests, even when a template exists.
-
Lawrence Pit
Actually, why does the +create+ method respond with the resource, while +update+ (and +delete+) don't? If +create+ were to respond with an empty body and status :created and :location set, that would solve my problem. Any objections to modifying this in rails 3 ?
-
Ryan Bigg
- State changed from new to needs-more-info
Destroy wouldn't because that resource no longer exists. Please show how to reproduce this bug.
-
Lawrence Pit
mime_respond_test.rb has this test:
def test_using_resource_for_post_with_xml_yields_created_on_success with_test_route_set do @request.accept = "application/xml" post :using_resource assert_equal "application/xml", @response.content_type assert_equal 201, @response.status assert_equal "<name>david</name>", @response.body assert_equal "http://www.example.com/customers/13", @response.location end endWhich shows that when you create something it will respond with the resource in xml format in it's response body.
But in almost all my cases this default response shows a lot of stuff I don't want to expose.
So for me the solution would be to NOT respond with the resource, just like +update+ which doesn't do that either.
Alternatively if that's not the behaviour we want, then if I define a create.xml.builder file to control what gets exposed, then it should use that to build the xml on a successful create, and respond with status code 201. However, it responds with status code 200. The attached test shows this.
Furthermore, when the creation is not successful it should respond with the default API behavior as defined in the method +api_behavior+ in +responder.rb+. The attached test shows this issue too.
Which solution should we go for? As said, my preference would be that on a +post+ it will return with an empty response body always, just like with a +put+. However, this probably breaks backwards compatibility. Can we do that for rails 3.x, as that breaks a lot compared to 2.x anyways?
Last thought: is the reason to respond with the resource after a create that consuming clients might parse it to find e.g. the ID?
-
Evgeniy Dolzhenko
- Importance changed from to Low
+1 for "Ending with respond_with(@user, :status => :created) does not set the status to :created either." (I'm on RC)
While docs state that it should be possible http://github.com/rails/rails/blob/master/actionpack/lib/action_con...
-
Santiago Pastorino
- State changed from needs-more-info to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino
- State changed from open to stale
