Forum: Ruby on Rails Where are the best AJAX examples?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A24e589de07cb769a71f28aead957a48?d=identicon&s=25 Duane Morin (Guest)
on 2006-06-02 19:48
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!
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (Guest)
on 2006-06-02 20:20
Duane Morin 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.
2d8faed600ccc353943cb79993ce81c6?d=identicon&s=25 Danger Stevens (Guest)
on 2006-06-02 22:16
(Received via mailing list)
If you're really looking for how to implement Rails-styled AJAX and
Javascript then you're looking for http://script.aculo.us

    - Danger
This topic is locked and can not be replied to.