"render :nothing => true" returns empty plaintext file?
Since Rails 4, head
is now preferred over render :nothing
.1
head :ok, content_type: "text/html"# or (equivalent)head 200, content_type: "text/html"
is preferred over
render nothing: true, status: :ok, content_type: "text/html"# or (equivalent)render nothing: true, status: 200, content_type: "text/html"
They are technically the same. If you look at the response for either using cURL, you will see:
HTTP/1.1 200 OKConnection: closeDate: Wed, 1 Oct 2014 05:25:00 GMTTransfer-Encoding: chunkedContent-Type: text/html; charset=utf-8X-Runtime: 0.014297Set-Cookie: _blog_session=...snip...; path=/; HttpOnlyCache-Control: no-cache
However, calling head
provides a more obvious alternative to calling render :nothing
because it's now explicit that you're only generating HTTP headers.
UPDATE: This is an old answer for legacy Rails versions. For Rails 4+, see William Denniss' post below.
Sounds to me like the content type of the response isn't correct, or isn't correctly interpreted in your browser. Double check your http headers to see what content type the response is.
If it's anything other than text/html
, you can try to manually set the content type like this:
render :nothing => true, :status => 200, :content_type => 'text/html'