I know that Rails will attempt to render a 200 status code, along with a template matching the controller and action, if I don't call render
explicitly in the action.
Is there a way to prevent Rails from doing this, and return no HTTP status code at all? Or, could I have the controller render an invalid response? The short reason is that I am trying to make use of a delegate method in Objective C that fires only when an HTTP request does not receive a valid response.
Thank you!
Or, could I have the controller render an invalid response?
Sure, if you don't want to send any body with your response you could just write in your controller:
head :bad_request
If you want to render and still sends and invalid response code:
render status: 500
render status: :forbidden
Everything can be found in the documentation here: http://guides.rubyonrails.org/layouts_and_rendering.html#the-status-option
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.