Allow custom http status to respond_with #4290

Closed
masterkain opened this Issue Jan 4, 2012 · 2 comments

Comments

Projects
None yet
3 participants
Contributor

masterkain commented Jan 4, 2012

Specs revealed that respond_with ignores the :status parameter; it's my understanding that the status code derives from the passed object's state:

#201, 422
respond_with @media, location: my_location_url

:location instead can be overridden; I have a use case for an internal API to return a particular http status code in presence of a specific validation failure, while maintaining goodies like acts_as_api, which is wrapping respond_with to render a custom representation of the object:

respond_with @media, api_template: :v2_private_only_file_name, location: my_location_url, status: :conflict

The parameter status is being ignored, so I'd like to know if there's a consensus about letting the developer override it for specific calls.

Owner

tenderlove commented Jan 4, 2012

Can you write a test case that shows the problem? It looks like Rails has tests for overriding the status:

https://github.com/rails/rails/blob/master/actionpack/test/controller/mime_responds_test.rb#L978-987
https://github.com/rails/rails/blob/master/actionpack/test/controller/mime_responds_test.rb#L542-544

Some failing code would help! Thanks.

Member

josevalim commented Jan 5, 2012

What is happening here is that the default behavior for html in a successful post is to redirect. So there is no way Rails can redirect and set the status code to conflict. You need to override the html branch of your code or whatever navigational path you are using.

josevalim closed this Jan 5, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment