# Drop downs

**URL:** <https://www.ruby-forum.com/t/drop-downs/94246>\
**Category:** Rails\
**Created:** [April 26, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/drop-downs/94246 "2006-04-26T14:17:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bcnice99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecc23a/32.png) [@bcnice99](https://www.ruby-forum.com/u/bcnice99)\
**Post date:** [April 26, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/drop-downs/94246/1 "2006-04-26T14:17:26Z")

</div>

I’m having trouble getting a second drop down populated based on the  
value from the first drop down. I’ve tried following some of the  
examples posted, but haven’t had any success. I’m new to RoR so any help  
would be appreciated. When the first drop down’s value gets changed, it  
calls the correct method in the controller and even finds the correct  
country areas, but the results are not getting displayed in the partial

- the second drop down just remains blank.  
Thanks for the help!

\*\*\*\*\*\*\*\*\*\*\*\*\* Controller  
def new  
@trip = Trip.new  
@countries = Country.find(:all)  
@country\_areas = []  
end  
def find\_areas\_for\_country  
@country\_areas = CountryArea.find(:all, :conditions =\> [“country\_id  
= :country”, params])  
render(:partial =\> “country\_area”, :collection =\> @country\_areas)  
end

\*\*\*\*\*\*\*\*\*\*\* form

 Country \<%= options\_from\_collection\_for\_select(@countries, "id", "descr") %\> \<%= observe\_field(:country, :update =\> "country\_area", :url =\> { :action =\> :find\_areas\_for\_country }, :with =\> "'country='+value") %\> Area \<%= render :partial =\> 'country\_area' %\> 

\*\*\*\*\*\*\*\*\*\* partial  
  
\<%= options\_from\_collection\_for\_select(@country\_areas, “id”, “descr”) %\>

---

<div class="post-metadata">

**Author:** ![bcnice99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecc23a/32.png) [@bcnice99](https://www.ruby-forum.com/u/bcnice99)\
**Post date:** [April 26, 2006, 3:15pm UTC](https://www.ruby-forum.com/t/drop-downs/94246/2 "2006-04-26T15:15:48Z")

</div>

Brian N. wrote:

> \*\*\*\*\*\*\*\*\*\*\* form
> 
> Country \<%= options\_from\_collection\_for\_select(@countries, "id", "descr") %\> \<%= observe\_field(:country, :update =\> "country\_area", :url =\> { :action =\> :find\_areas\_for\_country }, :with =\> "'country='+value") %\> Area \<%= render :partial =\> 'country\_area' %\> 
> 
> \*\*\*\*\*\*\*\*\*\* partial  
>   
> \<%= options\_from\_collection\_for\_select(@country\_areas, “id”, “descr”) %\>

You don’t seem to have a div or span with an id of country\_area. tthe  
:update =\> … bit of the observe\_field is looking to replcace the  
contents of an element with the results of the action, you need a div to  
render into.

Alan.

---

<div class="post-metadata">

**Author:** ![bcnice99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecc23a/32.png) [@bcnice99](https://www.ruby-forum.com/u/bcnice99)\
**Post date:** [April 26, 2006, 3:17pm UTC](https://www.ruby-forum.com/t/drop-downs/94246/3 "2006-04-26T15:17:44Z")

</div>

Alan F. wrote:

> You don’t seem to have a div or span with an id of country\_area. tthe  
> :update =\> … bit of the observe\_field is looking to replcace the  
> contents of an element with the results of the action, you need a div to  
> render into.

Jyst noticed the countray\_area id is used inside the partial. this  
won’t work as the particl needs rendered _into_ country\_area. In your  
case, that should probably be the td(\*).

Alan  
(\*)But be wary of DOM manipulation and tables in IE

---

<div class="post-metadata">

**Author:** ![bcnice99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecc23a/32.png) [@bcnice99](https://www.ruby-forum.com/u/bcnice99)\
**Post date:** [April 27, 2006, 4:24am UTC](https://www.ruby-forum.com/t/drop-downs/94246/4 "2006-04-27T04:24:58Z")

</div>

Alan F. wrote:

> Alan F. wrote:
> 
> > You don’t seem to have a div or span with an id of country\_area. tthe  
> > :update =\> … bit of the observe\_field is looking to replcace the  
> > contents of an element with the results of the action, you need a div to  
> > render into.
> 
> Jyst noticed the countray\_area id is used inside the partial. this  
> won’t work as the particl needs rendered _into_ country\_area. In your  
> case, that should probably be the td(\*).
> 
> Alan  
> (\*)But be wary of DOM manipulation and tables in IE

Thanks that seems to work! I also had to change the line in the  
controller to use :object rather than :collection

```
render(:partial => "country_area", :object => @country_areas)

```

Thanks again
