Forum: Ruby on Rails redner 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.
C4bfcc81ac9281cb905f38e97e4d4e0b?d=identicon&s=25 Shandy Nantz (snantz)
on 2007-07-23 16:36
I just want to get some feedback and understanding on what the
differences are between render and redirect_to. redirect_to post the
info to the page you are redirecting to and redner simple does not post,
correct? Thanks,

~S
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 unknown (Guest)
on 2007-07-23 16:58
(Received via mailing list)
Hi --

On Mon, 23 Jul 2007, Shandy Nantz wrote:

>
> I just want to get some feedback and understanding on what the
> differences are between render and redirect_to. redirect_to post the
> info to the page you are redirecting to and redner simple does not post,
> correct? Thanks,

It's easiest to understand if you consider that every action contains
an implicit render command:

   def show
     @item = Item.find(params[:id])
     # render the template show.rhtml
   end

So when you do:

   def show
     @item = Item.find(params[:id])
     render :template => "showme"    # alternate template
   end

or:

   def show
     render :text => "No showing today!"
   end

you're just completing this request in a non-default way.

redirect_to, on the other hand, issues a whole new request.  The whole
request/response cycle starts again from the beginning: a new action,
new instance variables, etc.

Here's an analogy (please ignore if unhelpful :-)

Every day you put on a shirt.  You might have a default shirt for each
day -- but sometimes you might wear a non-default shirt for a given
day.  Putting on a shirt is like rendering a view.

redirect_to is like it's a whole new day.  The process has started
again from the beginning.


David

--
* Books:
   RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242)
   RUBY FOR RAILS (http://www.manning.com/black)
* Ruby/Rails training
     & consulting:  Ruby Power and Light, LLC (http://www.rubypal.com)
C4bfcc81ac9281cb905f38e97e4d4e0b?d=identicon&s=25 Shandy Nantz (snantz)
on 2007-07-23 18:18
That makes perfect sense and explains why when I was trying to retreive
data from the parameters hash that nothing was there. I'm new to RoR and
it seems like every now and then I discover a little quark that throws
me for a loop. Your book, by the way, was one of the books that I read
to learn RoR - very well written. Thanks again,

~S
This topic is locked and can not be replied to.