# Multipe Combo box Query System

**URL:** <https://www.ruby-forum.com/t/multipe-combo-box-query-system/195436>\
**Category:** Rails\
**Created:** [September 23, 2010, 8:58am UTC](https://www.ruby-forum.com/t/multipe-combo-box-query-system/195436 "2010-09-23T08:58:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![PalaniKannan\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eb8c5e/32.png) [@PalaniKannan\_K](https://www.ruby-forum.com/u/PalaniKannan_K)\
**Post date:** [September 23, 2010, 8:58am UTC](https://www.ruby-forum.com/t/multipe-combo-box-query-system/195436/1 "2010-09-23T08:58:14Z")

</div>

Hi,

Anybody tell me, how i can implement multiple query system which is  
related  
hierarchically ?

Like

1. Year,
2. Files in that selected year.

–  
With Regards  
Palani Kannan. K

---

<div class="post-metadata">

**Author:** ![PalaniKannan\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eb8c5e/32.png) [@PalaniKannan\_K](https://www.ruby-forum.com/u/PalaniKannan_K)\
**Post date:** [September 23, 2010, 9:56am UTC](https://www.ruby-forum.com/t/multipe-combo-box-query-system/195436/2 "2010-09-23T09:56:13Z")

</div>

On 23 September 2010 07:57, PalaniKannan K [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,
> 
> Anybody tell me, how i can implement multiple query system which is related  
> hierarchically ?
> 
> Like
> 
> 1. Year,
> 2. Files in that selected year.

I think you will need to be a lot more specific about your  
requirement. I, for one, have little idea what you mean. If you are  
just talking about related tables (has\_many, belongs\_to etc) then have  
a look at the Rails Guide on ActiveRecord Relationships.

Colin

---

<div class="post-metadata">

**Author:** ![PalaniKannan\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eb8c5e/32.png) [@PalaniKannan\_K](https://www.ruby-forum.com/u/PalaniKannan_K)\
**Post date:** [September 23, 2010, 12:58pm UTC](https://www.ruby-forum.com/t/multipe-combo-box-query-system/195436/3 "2010-09-23T12:58:54Z")

</div>

Dear Collin,

Sorry for failing in explaining the problem. I wish to apply like

1. collection\_select (country)
2. collection\_select (state)
3. collection\_select (city)

I need to give the query system hierarchically.

(Eg. select India → then it should populate states in India-\> select  
state  
tamilnadu-\> it should populate cities in tamilnadu-\> select madras-\> It  
should get all params values as params[:country], :params[:state],  
:params[city]-\>@list = Table.find(conditions…params[:country],  
:params[:state], :params[city]))

This is the exact problem I need. In tutorials, this kind of hierarchal  
collection\_select options are not available… If clear tutorials  
available  
kindly tell me… With Advanced Thanks.

On 23 September 2010 09:54, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 1. Files in that selected year.  
> > “Ruby on Rails: Talk” group.  
> > To post to this group, send email to removed\_email\_address@domain.invalid.  
> > To unsubscribe from this group, send email to  
> > removed\_email\_address@domain.invalid[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > .  
> > For more options, visit this group at  
> > [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–  
With Regards  
Palani Kannan. K

---

<div class="post-metadata">

**Author:** ![PalaniKannan\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eb8c5e/32.png) [@PalaniKannan\_K](https://www.ruby-forum.com/u/PalaniKannan_K)\
**Post date:** [September 23, 2010, 4:41pm UTC](https://www.ruby-forum.com/t/multipe-combo-box-query-system/195436/4 "2010-09-23T16:41:29Z")

</div>

You should look into:

> <https://stackoverflow.com/questions/575862/rjs-using-observe-field-on-select-tag>

for info on how to use observe\_field in combination with a select. I  
just did a sursory review, and it looks like a decent solution  
guideline.

---

<div class="post-metadata">

**Author:** ![PalaniKannan\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eb8c5e/32.png) [@PalaniKannan\_K](https://www.ruby-forum.com/u/PalaniKannan_K)\
**Post date:** [September 27, 2010, 8:00am UTC](https://www.ruby-forum.com/t/multipe-combo-box-query-system/195436/5 "2010-09-27T08:00:35Z")

</div>

On Sep 23, 3:52 am, PalaniKannan K [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
…

> 1. collection\_select (country)
> 2. collection\_select (state)
> 3. collection\_select (city)  
> …  
> (Eg. select India → then it should populate states in India-  
> …  
> You can add onchange to 1 and 2 above, eg.  
> collect\_select( …,  
> :onchange=\>  
> remote\_function(:url=\>controllers\_path, :method=\>:get,  
> :with=\>‘’  
> ‘country=’+options[selectedIndex].value" ) )

where “controllers\_path” is a path to an action that,

Or you could write some unobtrusive jQuery code to perform similarly.

Jeff

---

<div class="post-metadata">

**Author:** ![PalaniKannan\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eb8c5e/32.png) [@PalaniKannan\_K](https://www.ruby-forum.com/u/PalaniKannan_K)\
**Post date:** [September 27, 2010, 11:07am UTC](https://www.ruby-forum.com/t/multipe-combo-box-query-system/195436/6 "2010-09-27T11:07:16Z")

</div>

Ryan B. did an excellent screencast that does exactly just that:

> **[\#88 Dynamic Select Menus - RailsCasts](http://railscasts.com/episodes/88-dynamic-select-menus)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

Supposedly this plugin does the same thing

> **[GitHub - splendeo/dependent\_select: Handles the typical country-province-city...](https://github.com/splendeo/dependent_select)**
>
> Handles the typical country-province-city dependent select problem - GitHub - splendeo/dependent\_select: Handles the typical country-province-city dependent select problem

Haven’t tried it personally, so can’t vouch for it.

-sunny  
[http://ezror.com](http://ezror.com)

---

<div class="post-metadata">

**Author:** ![PalaniKannan\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/eb8c5e/32.png) [@PalaniKannan\_K](https://www.ruby-forum.com/u/PalaniKannan_K)\
**Post date:** [September 27, 2010, 10:07am UTC](https://www.ruby-forum.com/t/multipe-combo-box-query-system/195436/7 "2010-09-27T10:07:01Z")

</div>

Dear Jeff,

Thank you very much… Excellent.

On 27 September 2010 07:59, JeffV [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You can add onchange to 1 and 2 above, eg.  
> Jeff

–  
With Regards  
Palani Kannan. K
