# Where are the best AJAX examples?

**URL:** <https://www.ruby-forum.com/t/where-are-the-best-ajax-examples/95478>\
**Category:** Rails\
**Created:** [June 2, 2006, 7:48pm UTC](https://www.ruby-forum.com/t/where-are-the-best-ajax-examples/95478 "2006-06-02T19:48:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmorin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@dmorin](https://www.ruby-forum.com/u/dmorin)\
**Post date:** [June 2, 2006, 7:48pm UTC](https://www.ruby-forum.com/t/where-are-the-best-ajax-examples/95478/1 "2006-06-02T19:48:20Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![dmorin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@dmorin](https://www.ruby-forum.com/u/dmorin)\
**Post date:** [June 2, 2006, 8:20pm UTC](https://www.ruby-forum.com/t/where-are-the-best-ajax-examples/95478/2 "2006-06-02T20:20:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dmorin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f0a364/32.png) [@dmorin](https://www.ruby-forum.com/u/dmorin)\
**Post date:** [June 2, 2006, 10:16pm UTC](https://www.ruby-forum.com/t/where-are-the-best-ajax-examples/95478/3 "2006-06-02T22:16:53Z")

</div>

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

```
- Danger

```
