Cayce Balara
2006-Oct-12 12:46 UTC
diff between redirect_to :action and calling action/render?
I''ve seen these two constructs used in different places and was wondering if someone could explain the differences in use, ie why one or the other in specific situations... def index redirect_to :action => ''list'' end or def index list render :action => ''list'' end thanks. c. -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2006-Oct-12 13:04 UTC
Re: diff between redirect_to :action and calling action/rend
redirect sends back a response to the browser telling it to load a new url instead of the one requested, whereas render doesn''t(since it just changes the template used Fred -- 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 -~----------~----~----~----~------~----~------~--~---
Cayce Balara
2006-Oct-12 13:32 UTC
Re: diff between redirect_to :action and calling action/rend
Thanks for the quick response, Frederick. soooo... In first case the URL in the browser will say: http://site.com/controller/list and in the second it will say: http://site.com/controller/index? But otherwise the net result of what code is processed and what content is displayed is the same? Thanks. c. Frederick Cheung wrote:> redirect sends back a response to the browser telling it to load a new > url instead of the one requested, whereas render doesn''t(since it just > changes the template used > > Fred-- 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 -~----------~----~----~----~------~----~------~--~---
Anthony Carlos
2006-Oct-12 13:33 UTC
Re: diff between redirect_to :action and calling action/rend
Some of the consequences of using render is that the browser''s url remains whatever what was used to generate the request. redirect, since it asks the browser to generate a new request, has the side effect of changing the browser''s url. This allows you to do things that are more resilient to users using the back button or hitting reload. The pattern is called "Redirect after Post" and you can google it to find out more details. In short, if you''ve done some kind of operation that changes the state of the system, such as updating or creating a model object, you should redirect to different page. Thus, hitting reload on the browser won''t try to update the system again. Hope it helps, -Anthony On Oct 12, 2006, at 9:04 AM, Frederick Cheung wrote:> > redirect sends back a response to the browser telling it to load a new > url instead of the one requested, whereas render doesn''t(since it just > changes the template used > > Fred > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2006-Oct-12 13:43 UTC
Re: diff between redirect_to :action and calling action/rend
Cayce Balara wrote:> Thanks for the quick response, Frederick. > > > soooo... > > In first case the URL in the browser will say: > > http://site.com/controller/list > > and in the second it will say: > > http://site.com/controller/index? >that is correct.> > But otherwise the net result of what code is processed and what content > is displayed is the same?That should normally be the case. An example of when you would want to do a redirect rather than a render would be if you had an an action that added something to your list: if you do a render then if the user does a refresh then they will call your add action, whereas if you redirect to the list action in the add action then refreshing the page will just show the list again, rather than calling add again. Fred -- 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 -~----------~----~----~----~------~----~------~--~---
Thorsten L
2006-Oct-12 13:51 UTC
Re: diff between redirect_to :action and calling action/rend
Cayce Balara wrote:> Thanks for the quick response, Frederick. > > > soooo... > > In first case the URL in the browser will say: > > http://site.com/controller/list > > and in the second it will say: > > http://site.com/controller/index? > > > But otherwise the net result of what code is processed and what content > is displayed is the same? > > Thanks. > c.....uhm... not exactly. - redirect_to makes the browser load a new page, and the result is the same as if the user manually nagivated to this URL or entered it in the address field of his browser. so to stick to your example: once the browser has requested the new page he has been redirected to (controller/list), the "list" action will be executed, and then the corresponding view will be parsed and filled with the data made available to it in the action. - render will only render the view of the "list" action (list.rhtml) without calling the "list" action first. So you would have to make some data availabe in the index action that can be parsed in the "list" view file, which would not be very DRY (Don''t repeat Yourself) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Cayce Balara
2006-Oct-12 18:00 UTC
Re: diff between redirect_to :action and calling action/rend
Things are coming very clear - thanks to everyone for input. c. -- 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 -~----------~----~----~----~------~----~------~--~---