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" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeremy Kemper
2007-Jan-03 13:18 UTC
Re: `render :nothing => true` whines about "missing template".
On 1/3/07, Chris <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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?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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeremy Kemper wrote:> On 1/3/07, Chris <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---