Topic: select drop downs

okay I'm having a little problem with these in rails.
I can make a drop down from a specified list no problem
and I can make a dynamic one from db entries no problem.

whats stumped me is making a drop down with both.

basically I want a drop down with the first couple of entries pre-defined and the rest based on the database. I've tried combine the arrasy with concat but keeps bringing up an error.

if anybody has a good resource or some advice on these please let me know.


Re: select drop downs

The array that Find(:all).map returns is an array of arrays, so I think you will have to append an array to the end or beginning of the array, not just two values.

In my program I use this, which is probably very similar to what you have:

select(:order, :companies_id, Company.find(:all).map {|u| [,] })

So in your case I would do something like

@company_array = Company.find(:all).map {|u| [,]}

The brackets [] signify an array, so you are pushing (appending) an array to the end of your array. The two elements of this array are "default1" and 1.

Then your select field code would be

select(:order, :companies_id,  @company_array)

This would add the string default1 to the end of the drop down list. If you want the hand coded ones at the beginning just insert them to the beginning of the array instead of pushing them at the end.

I hope this helps!

Last edited by dahuk (2006-11-13 13:11:38)