Forum: Ruby on Rails What is difference between render & redirect methods?

8c70506408fddb9740b4de7339055c77?d=identicon&s=25 Prashant Tiwari (tiwaripk)
on 2006-03-22 10:53
Hi,
Thest are two methods:-
1) redirect_to :action => 'list'
2) render :action => 'list'

what is difference between these two methods??????

Thanks.
Prash
Bf66e10c8fc4abefebde0425e7f6f15a?d=identicon&s=25 Norman Timmler (Guest)
on 2006-03-22 11:20
(Received via mailing list)
Am Mittwoch, den 22.03.2006, 10:53 +0100 schrieb Prashant Tiwari:
> Hi,
> Thest are two methods:-
> 1) redirect_to :action => 'list'
> 2) render :action => 'list'
>
> what is difference between these two methods??????

redirect_to :action => 'list' forces the clients browser to request the
list action.

render :action => 'list' will render the template list.rhtml without
calling or redirecting to the list action.
--
Norman Timmler

http://blog.inlet-media.de
59de94a56fd2c198f33d9515d1c05961?d=identicon&s=25 Tom Mornini (Guest)
on 2006-03-22 11:22
(Received via mailing list)
On Mar 22, 2006, at 1:53 AM, Prashant Tiwari wrote:
> Thest are two methods:-
> 1) redirect_to :action => 'list'

This causes an HTTP redirect to be returned to the browser,
which then fetches the new URL.

> 2) render :action => 'list'

This causes a 'server side' redirect, and causes
the other action to be executed without the browser
knowing anything about the change.

> what is difference between these two methods??????

--
-- Tom Mornini
Bf66e10c8fc4abefebde0425e7f6f15a?d=identicon&s=25 Norman Timmler (Guest)
on 2006-03-22 11:37
(Received via mailing list)
Am Mittwoch, den 22.03.2006, 02:21 -0800 schrieb Tom Mornini:
> On Mar 22, 2006, at 1:53 AM, Prashant Tiwari wrote:
> > 2) render :action => 'list'
>
> This causes a 'server side' redirect, and causes
> the other action to be executed without the browser
> knowing anything about the change.

That's wrong. The action never gets called. Only the template for that
action is rendered.

http://api.rubyonrails.com/classes/ActionControlle...

--
Norman Timmler

http://blog.inlet-media.de
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2006-03-22 11:41
(Received via mailing list)
On Mar 22, 2006, at 11:21, Tom Mornini wrote:

> This causes a 'server side' redirect, and causes
> the other action to be executed without the browser
> knowing anything about the change.

Almost. The action is not executed, only the corresponding template
list.rhtml is rendered as if the call was

    render :view => 'list' # imaginary API

being equivalent to

    render :template => "#{controller_name}/list.rhtml"

modulus the template extension. It could even happen that the list
action renders something else.

Server-side "redirects" are done with render_component.

-- fxn
4005a47a8f2ceee49670b920593c1d52?d=identicon&s=25 Ben Munat (Guest)
on 2006-03-22 17:37
(Received via mailing list)
Xavier Noria wrote:
>    render :view => 'list' # imaginary API
>
> being equivalent to
>
>    render :template => "#{controller_name}/list.rhtml"
>
> modulus the template extension. It could even happen that the list
> action renders something else.
>
> Server-side "redirects" are done with render_component.

Hmm, I never knew this... seems like an unfortunate decision, bound to
create confusion.

b
59de94a56fd2c198f33d9515d1c05961?d=identicon&s=25 Tom Mornini (Guest)
on 2006-03-22 18:21
(Received via mailing list)
> On Mar 22, 2006, at 11:21, Tom Mornini wrote:
>
>> This causes a 'server side' redirect, and causes
>> the other action to be executed without the browser
>> knowing anything about the change.

On Mar 22, 2006, at 2:41 AM, Xavier Noria wrote:

> Almost. The action is not executed, only the corresponding template
> list.rhtml is rendered as if the call was

On Mar 22, 2006, at 2:37 AM, Norman Timmler wrote:

> That's wrong. The action never gets called. Only the template for that
> action is rendered.
>
> http://api.rubyonrails.com/classes/ActionControlle...

Thanks for the corrections, Xavier and Norman!

I hate it when I do that! :-)

--
-- Tom Mornini
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2006-03-22 18:23
(Received via mailing list)
On Mar 22, 2006, at 18:21, Tom Mornini wrote:

>
> I hate it when I do that! :-)
Heh, nevermind, I learnt it the hard way a while back :-).

-- fxn
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.