Redner and redirect_to

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

Hi –

On Mon, 23 Jul 2007, Shandy N. 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 :slight_smile:

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

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