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:
Contexts:<%= collection_select(“task”, “context” , @contexts,
“id”,
“fullName”, {}) %>

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

Any suggestions?

Thanks in advance,

Alan

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
model.

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!!

–Alan

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs