Forum: Ruby on Rails format.html and redirect_to

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.
815f87acd945a1a6fcd05b5545ae76c9?d=identicon&s=25 Ricky (Guest)
on 2009-01-28 11:30
(Received via mailing list)
I was wondering what the purpose of wrapping a redirect_to in a
format.html block is. I get why you'd want to do this with a render,
but if you're redirecting the browser to another URL, what's the
point? As I understand it, when redirect_to is called, Rails sends a
302 back to the browser, so I'm having trouble understanding why
format plays any part in this. No biggie, just need some clarification
on what's actually happening.

Cheers,
Ricky
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-01-28 14:39
(Received via mailing list)
On 28 Jan 2009, at 10:30, Ricky <ricky@rickyrobinson.id.au> wrote:

>
> I was wondering what the purpose of wrapping a redirect_to in a
> format.html block is. I get why you'd want to do this with a render,
> but if you're redirecting the browser to another URL, what's the
> point? As I understand it, when redirect_to is called, Rails sends a
> 302 back to the browser,

It might not be a browser. Eg with a create action you would typically
redirect browsers to the show action, but the XML api probably
wouldn't do that.

Fred
815f87acd945a1a6fcd05b5545ae76c9?d=identicon&s=25 Ricky (Guest)
on 2009-01-29 00:43
(Received via mailing list)
> It might not be a browser. Eg with a create action you would typically  
> redirect browsers to the show action, but the XML api probably  
> wouldn't do that.

Thanks for responding Fred.

So are you saying that sometimes a redirect is not actually a redirect
in the 302 sense of the word? Rather that, sometimes, a redirect
*does* result in actual content being sent back to the browser/AJAX
component?

Rick
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-01-29 01:24
(Received via mailing list)
On 28 Jan 2009, at 23:42, Ricky wrote:

> *does* result in actual content being sent back to the browser/AJAX
> component?
>
A redirect is always a redirect. What i'm saying is that sometimes you
don't want to redirect, in the aforementioned xml api example you'd
probably just respond with an empty response with the appropriate http
status code. An ajaxified interface is also a place where you might
not want to do a redirect (you'd just return some html to be inserted
into the DOM or produce some javascript to execute).

Fred
815f87acd945a1a6fcd05b5545ae76c9?d=identicon&s=25 Ricky (Guest)
on 2009-02-23 08:25
(Received via mailing list)
> A redirect is always a redirect. What i'm saying is that sometimes you  
> don't want to redirect, in the aforementioned xml api example you'd  
> probably just respond with an empty response with the appropriate http  
> status code. An ajaxified interface is also a place where you might  
> not want to do a redirect (you'd just return some html to be inserted  
> into the DOM or produce some javascript to execute).

What I wasn't understanding was that the format.xxx methods were
acting similarly to case statements. So the appropriate block of code
is executed depending on what the mime format is. With that tiny
tidbit of knowledge, it all becomes completely comprehensible.

Rick
This topic is locked and can not be replied to.