Craig Ambrose
2005-Jun-24 08:01 UTC
components, render_component_as_string, and redirecting
Hi folks, I''m trying to "componentise" part of my application, and I''ve descovered that if I call my component using "render_component_as_string", and then do a "redirect_to" inside the component, it doesn''t actually redirect, it just outputs a like saying "You are being redirected." (with the a link to where I want to redirect to). This works fine if I use "render_component" instead, but I really want to render it as a string. I can kind of see why it can''t do the redirect in this case. However, I''m sure there must be a way around it. Anyone know of one? thanks Craig -- Craig Ambrose Web Elements http://www.portallus.com/people/craigambrose/
Craig Ambrose
2005-Jun-25 00:43 UTC
Re: components, render_component_as_string, and redirecting
It turns out that if a re-direct occurs during render_component_as_string, it''s still written to @headers["location"] in the ''parent'' controller (the controller telling the other component to render). However, nothing is done about it by the parent, so the best that the child can do is display the "you are being redirected" screen. I''ve found that if you add the following line to the ''parent'' controller, straight after calling render_component_as_string then it works as expected. redirect_to(@headers["location"]) if @headers["location"] Obviously, I think it would be good if rails did this itself. :) Craig On Fri, 24 Jun 2005 6:01 pm, Craig Ambrose wrote:> I''m trying to "componentise" part of my application, and I''ve descovered > that if I call my component using "render_component_as_string", and then do > a "redirect_to" inside the component, it doesn''t actually redirect, it just > outputs a like saying "You are being redirected." (with the a link to where > I want to redirect to).-- Craig Ambrose Web Elements http://www.portallus.com/people/craigambrose/