This seems to be basic but I'm a Ruby/Rails beginner. I need to simply return HTTP 204 in a controller. Would
respond_to do |format| format.html end
return a 204?
HTTP Status 204 (No Content) indicates that the server has successfully fulfilled the request and that there is no content to send in the response payload body.
render :json essentially calls to_json and returns the result to the browser with the correct headers. This is useful for AJAX calls in JavaScript where you want to return JavaScript objects to use. Additionally, you can use the callback option to specify the name of the callback you would like to call via JSONP.
head :no_content
Tested with Rails 3.2.x, 4.x. It causes the controller method to respond with the 204 No Content HTTP status code.
An example of using this inside a controller method named foobar
:
def foobar head :no_content end
Look at the head method:
Return a response that has no content (merely headers). The options argument is interpreted to be a hash of header names and values.
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