Hey All,
I'm still working on my 'add people to this project' feature for my / projects/edit view. I've got a very nice AJAX search feature (thanks to the kind help here) that allows users to generate a list of people to potentially add to the project they're editing. I've also got an AJAX 'add this found person to this project' feature MOSTLY working-- am writing for help on fixing the last issue w/that.
Model wise, I've got Project & Person in a many-to-many, and ProjectPerson as the join model (so, Project has_many :people, :through => :project_person). The join model ProjectPerson has just one attribute of its own--role. My problem is that I can't figure out how to allow the user to edit this field before adding the association between the Project and the Person.
Here's the code I'm using to do the add. The AJAX search feature renders a partial that spits one of these out for each person meeting the search:
<td><%= h p.person.nom %> </td> <td><%= h p.person.organization.abbreviation %></td> <td><%= select(p, :role, Person::ROLE_NAMES, :selected => p.person.typical_role) %> </td> <td class='list-actions'> <%= link_to_remote('Add', :url => {:controller => "project_people", :action => "create", :person_id => p.person, :project_id => p.project, :role => p.role #<-- Problem is here. }, :update => 'roster', :method => 'post' ) %> </td>
('p' here is an instance of ProjectPerson). The select() helper gives me a nice drop-down, and p.person and p.project are both getting properly transmitted to the project_people.create action, but p.role is always blank. I suspect this is b/c at the time this is transmuted into HTML/javascript, p.role is blank, and there's nothing in my link_to_remote() call to tell the browser to go get whatever the user put in the drop-down corresponding to the call to select(). If that's it, I don't know how to do that (and when I go to 'view source' on the page the AJAXy bits don't show up, so I don't know how to investigate that). Assuming anybody's read this far, can you advise? (Do I need to use remote_form_for maybe?)
Inicdentally, if I change the indicated argument to:
:role => p.person.typical_role
Then I do indeed get the contents of person.typical_role written to project_person.role. But I really want to allow the user to override that.
A thousand thanks in advance!
-Roy