# Dynamic collection\_select

**URL:** <https://www.ruby-forum.com/t/dynamic-collection-select/178688>\
**Category:** Rails\
**Created:** [November 9, 2009, 5:44pm UTC](https://www.ruby-forum.com/t/dynamic-collection-select/178688 "2009-11-09T17:44:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [November 9, 2009, 5:44pm UTC](https://www.ruby-forum.com/t/dynamic-collection-select/178688/1 "2009-11-09T17:44:03Z")

</div>

Hello all,  
I’m very new to Ruby and web programming at all. I’m trying to get a  
page where I can have a series of drop downs that are all columns within  
the main table of my database. When you drop one down, and select a  
value, I want the others to update with their possible options based on  
the first selection. For example, the model is employees:

If you use the drop down for ‘title’, and select Vice President, then in  
the rest of the drop downs, the only options will be related to those  
who are VPs. I hope this makes sense. I just got the collection\_select  
to populate on my view, but I don’t know where to go from here or how to  
pass that value back to a controller function.

I’ve read several blog posts and books, but they don’t’ seem to be  
addressing exactly what I’m doing. THANKS!

---

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [November 9, 2009, 6:35pm UTC](https://www.ruby-forum.com/t/dynamic-collection-select/178688/2 "2009-11-09T18:35:44Z")

</div>

I think you need AJAX here to populate the cascade “rest of the drop  
downs” or refresh the whole page on change of the first drop down and  
feed the collection\_seelct in the controller with appropriate data.

---

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [November 9, 2009, 7:08pm UTC](https://www.ruby-forum.com/t/dynamic-collection-select/178688/3 "2009-11-09T19:08:55Z")

</div>

Michal B. wrote:

> I think you need AJAX here to populate the cascade “rest of the drop  
> downs” or refresh the whole page on change of the first drop down and  
> feed the collection\_seelct in the controller with appropriate data.

Damn,  
I was hoping I wouldn’t have to do that. I know there is some AJAX that  
is included with ROR, anyway to envoke that her? How about an easier  
one - once I have selected my value in a collection\_select, what do I do  
next - how do I pass that selected value back into a controller for  
another page - with the results based on that one dropdown box?

---

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [November 9, 2009, 8:06pm UTC](https://www.ruby-forum.com/t/dynamic-collection-select/178688/4 "2009-11-09T20:06:25Z")

</div>

Typically for a form, with a “submit” button.

-eric

On Nov 9, 10:08 am, Brian H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [November 9, 2009, 8:07pm UTC](https://www.ruby-forum.com/t/dynamic-collection-select/178688/5 "2009-11-09T20:07:03Z")

</div>

Brian H. wrote:

> Michal B. wrote:
> 
> > I think you need AJAX here to populate the cascade “rest of the drop  
> > downs” or refresh the whole page on change of the first drop down and  
> > feed the collection\_seelct in the controller with appropriate data.
> 
> Damn,  
> I was hoping I wouldn’t have to do that. I know there is some AJAX that  
> is included with ROR, anyway to envoke that her?

Don’t. Learn to write JavaScript properly before you try to have Rails  
automate it.

(Hint: _proper_ JavaScript is not mixed in with HTML.)

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
