Forum: Ruby on Rails `render :nothing => true` whines about "missing template".

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Chris (Guest)
on 2007-01-03 13:10
In FooController, I put method #bar whose only purpose is to run some
logic in the background and return a status 204 [1].

So in order to return only the 204 status code, I put at the end of
#bar:

`render :nothing => true, :status => 204`

But then when surfing to /foo/bar, I get an error about "missing
template bar.rhtml". Is this a bug?

(The solution eventually was `render :text => ''`, but it really seems
like a hack and that `render => :nothing` should have been the valid
solution)

-Chris

[1] http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html - "204 No
Content: The server has fulfilled the request but does not need to
return an entity-body"
Jeremy K. (Guest)
on 2007-01-03 15:26
(Received via mailing list)
On 1/3/07, Chris <removed_email_address@domain.invalid> wrote:
> template bar.rhtml". Is this a bug?
It's hard to know without seeing a code sample. Perhaps your render call
is
lurking within a conditional?

Note that in 1.2 you can do "head 204" or "head :no_content" when you
have
nothing to render and just want to return a status and optional headers.
The symbolic status code is translated to 204 No Content (likewise for
head
:forbidden, head :whatever_status_code, etc.)

jeremy
Chris (Guest)
on 2007-01-03 16:19
Jeremy K. wrote:
> On 1/3/07, Chris <removed_email_address@domain.invalid> wrote:
>> template bar.rhtml". Is this a bug?
> It's hard to know without seeing a code sample. Perhaps your render call
> is
> lurking within a conditional?

I've checked again and the problem was with the way my testing browser
(FF 1.5.0.9 on Win32) interacted with the content-less response.

Probably because there was nothing to render, the browser simply
redisplayed the last rendered content, which happened to be the said
warning about missing template.

Rendering an empty string "fixed" this because the browser would then
display a blank page. My conusing was exacerbated by an additional
browser quirk: trying to refresh the page resulted in the browser
silently resending the last *rendered* request, i.e. the one which
emitted the "template missing" warning, instead of resending the request
that returned the blank 204.

> Note that in 1.2 you can do "head 204" or "head :no_content" when you
> have
> nothing to render and just want to return a status and optional headers.
> The symbolic status code is translated to 204 No Content (likewise for
> head
> :forbidden, head :whatever_status_code, etc.)

Thanks for all the information about 1.2. Not sure how much of an
improvement `head` is over `render :nothing => true`, which is nice
enough imho. However, being able to use symbolic status codes is
definitely a nifty feature!

-Chris

> jeremy
This topic is locked and can not be replied to.