collection_select

I am attempting to populate a collection_select object with data from a separate table than the one the collection will be displayed.

Specifically, I would like to add a new 'project', and in one of the fields, I would like to have a drop down list which shows different project types. Any advice on how to do this would be greatly appreciated.

controller

Thank you for the quick response. However, I must not have been clear in my question:

Assume that I have two tables: project, type

PROJECT contains columns: ID PROJECT_NAME TYPE_ID TYPE contains: ID TYPE_NAME

When I create a new project, I would like to have a #DDM, populated by the TYPE_NAME field.

CONTROLLER :

@type_list = Project.find(:all, :include => {:types=>{} }).collect{|x| x.type.type_name}.sort.uniq

in VIEW :

Thanks, that is a very tricky solution. I was starting from an empty project table, with a populated type table. I will include some dummy projects to feed this list. Am I correct in assuming that this is the necessary solution to this? It seems that querying the large product table will be more expensive than simply populating off of the smaller type table.

Thanks, that is a very tricky solution. I was starting from an empty project table, with a populated type table. I will include some dummy projects to feed this list. Am I correct in assuming that this is the necessary solution to this? It seems that querying the large product table will be more expensive than simply populating off of the smaller type table.

If you've got the types in a table, then

collection_select 'project', 'type', Type.find(:all), :type_name, :id

(assuming you're editing the instance variable @person). Before you do
any of this, choose a name that isn't type: that's used by rails for
single table inheritance

Fred

Perfect. I have been struggling with that all day. It worked like magic. Thanks for the help.

-Erik