Where are the best AJAX examples?


#1

Googling for this has not solved my problems. Is there a particular
site that is recommened for its examples and tutorials on Rails’ AJAX
capabilities? I know exactly what I want to do, just not how to do it,
and am looking for some code to pore over.

  1. I have a dropdown that represents the name of an image in a library.
    When the dropdown value is changed, I would like to refresh the current
    display and show the image that is now selected. Most of the examples
    I’m finding are during the remote submission of the form as a whole, I
    can’t seem to find much that executes on an onChange event.

  2. I have an object Foo that has_many Baz objects. During the creation
    or editing of a Foo object I’d like to independently be able to
    add/remove Baz objects without having to refresh the entire form each
    time. Is this even possible? I don’t necessarily want to update any of
    the other fields of the Foo object when somebody hits the “Add new Baz”
    button.

Thanks!


#2

Duane M. wrote:

Googling for this has not solved my problems. Is there a particular
site that is recommened for its examples and tutorials on Rails’ AJAX
capabilities? I know exactly what I want to do, just not how to do it,
and am looking for some code to pore over.

  1. I have a dropdown that represents the name of an image in a library.
    When the dropdown value is changed, I would like to refresh the current
    display and show the image that is now selected. Most of the examples
    I’m finding are during the remote submission of the form as a whole, I
    can’t seem to find much that executes on an onChange event.

  2. I have an object Foo that has_many Baz objects. During the creation
    or editing of a Foo object I’d like to independently be able to
    add/remove Baz objects without having to refresh the entire form each
    time. Is this even possible? I don’t necessarily want to update any of
    the other fields of the Foo object when somebody hits the “Add new Baz”
    button.

Thanks!

For #1 you don’t need ajax at all, just javascript.

<%= image_tag foo.image, :id => ‘image’ %>
<%= select ‘foo’, ‘image’,
[[‘image 1’, ‘/images/foo.jpg’], [‘image 2’, '/images/bar.jpg]],
:onchange => “$(‘image’).src = this.value” %>

Note that you still must submit the form to save this however.


#3

If you’re really looking for how to implement Rails-styled AJAX and
Javascript then you’re looking for http://script.aculo.us

- Danger