# AJAX and dynamic select lists

**URL:** <https://www.ruby-forum.com/t/ajax-and-dynamic-select-lists/84084>\
**Category:** Rails\
**Created:** [February 1, 2007, 7:06am UTC](https://www.ruby-forum.com/t/ajax-and-dynamic-select-lists/84084 "2007-02-01T07:06:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![petrjanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@petrjanda](https://www.ruby-forum.com/u/petrjanda)\
**Post date:** [February 1, 2007, 7:06am UTC](https://www.ruby-forum.com/t/ajax-and-dynamic-select-lists/84084/1 "2007-02-01T07:06:52Z")

</div>

Hey there 🙂  
Ive got clients and domains and a form containing this:

\<%=  
@clients = Client.find(:all, :order =\> “business\_name”)  
collection\_select(:service, :client\_id, @clients, :id, :business\_name)  
%\>

Then Ive got an observer field:

\<%=observe\_field(“service[client\_id]”, :update =\> :domains\_container,  
:url =\> {:action =\> :ajax\_domains}, :on =\> “changed”) %\>

and the 2nd select

\<%= @domains = Domain.find(:all, :order =\> "name ASC").map {|d| [d.name, d.id]} select(:service, :domain\_id, domains) %\>

And the controller bit:  
def ajax\_domains  
render\_text(“test”)  
end

For some reason “test” doesnt appear anywhere. it doesnt look like the  
observer is working.

Any clues?

Petr

---

<div class="post-metadata">

**Author:** ![petrjanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@petrjanda](https://www.ruby-forum.com/u/petrjanda)\
**Post date:** [February 1, 2007, 7:43am UTC](https://www.ruby-forum.com/t/ajax-and-dynamic-select-lists/84084/2 "2007-02-01T07:43:49Z")

</div>

And I do have

\<%=javascript\_include\_tag :defaults%\>

In the layout.

---

<div class="post-metadata">

**Author:** ![petrjanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@petrjanda](https://www.ruby-forum.com/u/petrjanda)\
**Post date:** [February 1, 2007, 8:51am UTC](https://www.ruby-forum.com/t/ajax-and-dynamic-select-lists/84084/3 "2007-02-01T08:51:36Z")

</div>

Petr J. wrote:

> Hey there 🙂  
> Ive got clients and domains and a form containing this:
> 
> \<%=  
> @clients = Client.find(:all, :order =\> “business\_name”)  
> collection\_select(:service, :client\_id, @clients, :id, :business\_name)  
> %\>

When I look at the HTML produced by

```
collection_select(:service, :client_id, ['1','2','3'], :to_s,:to_i)

```

I get

 1 2 3 

> Then Ive got an observer field:
> 
> \<%=observe\_field(“service[client\_id]”, :update =\> :domains\_container,  
> :url =\> {:action =\> :ajax\_domains}, :on =\> “changed”) %\>

So it seems your observe\_field should go for the id service\_client\_id,  
and not service[client\_id]

Stephan
