Ruby on Rails

link_to_remote

<html>
  <head>
    <title>Ajax Demo</title>

    <!-- tell rails to include prototype.js -->
    <%= javascript_include_tag "prototype" %>
    
  </head>
  <body>
      <h1>What time is it?</h1>
      <div id="time_div">
        I don't have the time, but
        
        <!-- Create a link which calls the server-side action /say-when -->
        <!-- and then updates the "time_div" div with the results -->
        <%= link_to_remote( "click here", :update => "time_div",
            :url =>{ :action => :say_when }) %>
        and I will look it up.
      </div>
    </body>
</html>

On the server side the action is
class DemoController < ApplicationController

  def index
  end

  def say_when
    render_text "<p>The time is <b>" + DateTime.now.to_s + "</b></p>"
  end
end

José M. Vidal .

14 of 16