Ruby on Rails

form_remote_tag

<html>
<head>
    <title>Ajax List Demo</title>
  <%= javascript_include_tag "prototype" %>
  </head>
    <body>
      <h3>Add to list using Ajax</h3>

      <!-- Start the Ajax form -->
      <%= form_remote_tag(:update => "my_list",
        :url => { :action => :add_item },
        :position => "top" ) %>

       New item text:

      <!-- Add a text field to this form -->
      <%= text_field_tag :newitem %>

      <!-- Add a submit button -->
      <%= submit_tag "Add item with Ajax" %>

      <!-- End the form: </form>-->
      <%= end_form_tag %>

      <ul id="my_list">
        <li>Original item... please add more!</li>
      </ul>
    </body>
</html>

On the server, the controller says:
class ListdemoController < ApplicationController

  def index
  end

  def add_item
    # Get the text the user typed in using params[:newitem]
    render_text "<li>" + params[:newitem] + "</li>"
  end
end

José M. Vidal .

15 of 16