dynamic collection_select

6 views
Skip to first unread message

Brian Harnett

unread,
Nov 9, 2009, 11:44:03 AM11/9/09
to rubyonra...@googlegroups.com
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!
--
Posted via http://www.ruby-forum.com/.

Michal Burak

unread,
Nov 9, 2009, 12:35:44 PM11/9/09
to rubyonra...@googlegroups.com
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.

Brian Harnett

unread,
Nov 9, 2009, 1:08:55 PM11/9/09
to rubyonra...@googlegroups.com
Michal Burak 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?

Eric

unread,
Nov 9, 2009, 2:04:49 PM11/9/09
to Ruby on Rails: Talk
Typically for a form, with a "submit" button.

-eric

On Nov 9, 10:08 am, Brian Harnett <rails-mailing-l...@andreas-s.net>
wrote:

Marnen Laibow-Koser

unread,
Nov 9, 2009, 2:07:03 PM11/9/09
to rubyonra...@googlegroups.com
Brian Harnett wrote:
> Michal Burak 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
mar...@marnen.org

Reply all
Reply to author
Forward
0 new messages