I'd like to set the response status value in particular action methods before the render method is called. Is this not possible?
Many of my methods in controllers render JSON API views for action methods like #destroy, #update, #create and those actions simply invoke #show or #index as is appropriate. However, I'd like to also return the appropriate HTTP Response status value, like 201, 202, etc, without having to pass arguments to these methods. Essentially, I am looking for something like this:
def destroy
# code that kills
status :accepted # ArgumentError, status= silently fails
index
end
if you just call
response.status = ###
in a controller, and then don't add the :status argument at render, it should get you what you need.
you can use the method render by passing the parameter :status, example :
render nothing: true, status: 201
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With