Using select to set a relationship class

I have two models:Task and Context

Task belongs_to Context
Context has_many Tasks

In my form partial for editing a task, I want to have a drop down with
of the contexts where you can select one for the task.

I tried:
Contexts:<%= collection_select(“task”, “context” , @contexts,
“fullName”, {}) %>

which doesn’t work for setting with the current value.

Any suggestions?

Thanks in advance,


Try changing the “id” param name in the collection_select method to
“context_id”, or whatever the name of the foreign key is within task

Let me know if that works.

Close. The solution I got to work was: Contexts:<%=
collection_select(“task”, “context_id” , @contexts, “id”, “fullName”,
{}) %>

Thanks for your help!!


On Jan 30, 2008 12:30 AM, Chris O. [email protected]