Trouble figuring out select tags

Sorry guys - such an obtuse question, but with all the myriad
possibilities out there for using select statements in my rails
template, I can’t figure out which one is the best. Here’s my problem: I
have a very simple form, which only does one thing: you select a name to
add to a project, click the submit button, and the form sends two
variables (the id of the name to add to the project (:addpersonid) plus
the id for the project for the redirect back(:id)) to an update function
very similar to the default scaffolding update function.

The names are pulled out of a model (Person), but I want to exclude any
names that are already on the project from the dropdown. Here’s my
pseudocode:

<% form_tag :action => ‘update’, :id => @id -%>

<% for p in @people -%>
<% unless @team.include?§ %>

<%= p.family_name, :action => “update”, :id => @id, :addpersonid =>
p.id %>

<% end %>
<% end -%>
<%= submit_tag ‘OK’ %>

<% end -%>

I don’t even know if this will work, but even if it does there’s got to
be a better way to do this. Anybody got any tips?

On 7/13/07, Sean C. [email protected] wrote:

p.id %>

<% end %>
<% end -%>
<%= submit_tag ‘OK’ %>

<% end -%>

I don’t even know if this will work, but even if it does there’s got to
be a better way to do this. Anybody got any tips?

Perhaps one way might be

<%= select_tag “addpersonid”,
options_from_collection_for_select( (@people - @team), :id,
:family_name )
-%>

Of course I’m not sure what the :action => ‘update’, :id => @id,
:addperson_id => p.id is in there for. This should be elsewhere in the
form
surely.

HTH
Daniel

Of course I’m not sure what the :action => ‘update’, :id => @id,
:addperson_id => p.id is in there for. This should be elsewhere in the
form
surely.

HTH
Daniel

Yes. That was a hasty cut and paste by me.
I ended up taking it out after I posted the message.
I will try your solution. It looks like the @people - @team part means
that you subtract anybody who is in @team from @people, right? Also not
sure what those asterisks are doing. But I will look it up in the API if
I can find it.

THANKS!

Sorry - maybe they’re only coming up as asterisks in my browser. This is
what I see:

<%= select_tag “addpersonid”,
options_from_collection_for_select( (@people - @team), :id,
:family_name )
-%>

In any case, I’ll disregard them. Thanks!

On 7/13/07, Sean C. [email protected] wrote:

In any case, I’ll disregard them. Thanks!
Must be the formatting from the copy/paste. Sorry about that.

Please do disregard those :slight_smile:

Cheers
Daniel

On 7/13/07, Sean C. [email protected] wrote:

Yes. That was a hasty cut and paste by me.
I ended up taking it out after I posted the message.
I will try your solution. It looks like the @people - @team part means
that you subtract anybody who is in @team from @people, right?

Yes. The association collections that AR returns are delegated to
Array.
So normal array operations mostly work.

Also not

sure what those asterisks are doing. But I will look it up in the API if
I can find it.

Not sure what asterisks you mean. I don’t see any.

Cheers
Daniel