# Combobox-distinct element

**URL:** <https://www.ruby-forum.com/t/combobox-distinct-element/183604>\
**Category:** Rails\
**Created:** [February 17, 2010, 7:14am UTC](https://www.ruby-forum.com/t/combobox-distinct-element/183604 "2010-02-17T07:14:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![veena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/51bf81/32.png) [@veena](https://www.ruby-forum.com/u/veena)\
**Post date:** [February 17, 2010, 7:14am UTC](https://www.ruby-forum.com/t/combobox-distinct-element/183604/1 "2010-02-17T07:14:07Z")

</div>

plz help me in retrieving distinct element from db and populate in  
combobox?

I hav created a model “location”.It has elements  
(state,district,province,…)  
I want to populate one combobox with distinct state and the other combo  
box should display corresponding districts in that state which is  
selected.

Can you give me the code for view, and controller

---

<div class="post-metadata">

**Author:** ![veena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/51bf81/32.png) [@veena](https://www.ruby-forum.com/u/veena)\
**Post date:** [February 17, 2010, 5:22pm UTC](https://www.ruby-forum.com/t/combobox-distinct-element/183604/2 "2010-02-17T17:22:27Z")

</div>

You can use .uniq! on any array (which includes  
ActiveRecord.find(:all…)  
return values).

In terms of setting the other combo boxes you’ll either need to ajax  
back to  
the controller or pass all data in the first time and have javascript do  
some filtering for you (which you choose depends on how much data you  
have).

My computer at home has something like this already coded. I’ll try to  
remember to put it up on github tonight or tomorrow.

---

<div class="post-metadata">

**Author:** ![veena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/51bf81/32.png) [@veena](https://www.ruby-forum.com/u/veena)\
**Post date:** [February 18, 2010, 5:00am UTC](https://www.ruby-forum.com/t/combobox-distinct-element/183604/3 "2010-02-18T05:00:41Z")

</div>

Ben Wiseley wrote:

> You can use .uniq! on any array (which includes  
> ActiveRecord.find(:all…)  
> return values).
> 
> In terms of setting the other combo boxes you’ll either need to ajax  
> back to  
> the controller or pass all data in the first time and have javascript do  
> some filtering for you (which you choose depends on how much data you  
> have).
> 
> My computer at home has something like this already coded. I’ll try to  
> remember to put it up on github tonight or tomorrow.

Thanks Ben…  
Plz forward me that code if possible.
