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 all of the contexts where you can select one for the task.

I tried:

<b>Contexts:</b><%= collection_select("task", "context" , @contexts, "id", "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:

<b>Contexts:</b><%= collection_select("task", "context_id" , @contexts, "id", "fullName", {}) %>

Thanks for your help!!