Making Ajax rerender in div

In Onlamp there is a wonderful introduction to Ajax under Rails in
"Ajax on Rails," ( ).

I have taken the Author, Curt Hibbs' code from the example, and in
looking at other examples, a common seeming problem (to me) keeps

If I want to render to a < div > element, when I make a subsequent
render to it, it then shows both this rendering as well as the previous
-- when in fact, I only want the latest rendering. The code for an
rhtml as well as a method coinciding with that rhtml bears this out.
How can I amend such code so as to only print the last link_to_remote
result? Also, would there be a way to render to, say, a textbox in this

Thank you. Ive looked at other Ajax on Rails examples and they all seem
to have this same 'problem,' which I'd like to get around.

    <title>Ajax Demo</title>
    <%= javascript_include_tag :defaults %>
    <h1>What time is it?</h1>
    <div id="time_div">
      I don't have the time, but
      <%= link_to_remote( "click here",
                          :update => "time_div",
                          :url => { :action => :say_when },
                          :position => "bottom" ) %>
      and I will look it up.

def say_when
      render_text "<p>The time is <b>" + + "</b></p>"

Try changing the code to render a partial. Also, don't use #render, use #replace_html. Try this:

def say_when
   replace_html "time_div",
                :partial => "time",

The problem here will be the entire div will get replaced by whatever HTML is in the partial. The "I don't have the time..." text will all get blown away so the user will only get to click on this once.