# Trouble figuring out select tags

**URL:** <https://www.ruby-forum.com/t/trouble-figuring-out-select-tags/109282>\
**Category:** Rails\
**Created:** [July 13, 2007, 3:49am UTC](https://www.ruby-forum.com/t/trouble-figuring-out-select-tags/109282 "2007-07-13T03:49:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [July 13, 2007, 3:49am UTC](https://www.ruby-forum.com/t/trouble-figuring-out-select-tags/109282/1 "2007-07-13T03:49:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [July 13, 2007, 4:03am UTC](https://www.ruby-forum.com/t/trouble-figuring-out-select-tags/109282/2 "2007-07-13T04:03:55Z")

</div>

On 7/13/07, Sean C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [July 13, 2007, 4:55am UTC](https://www.ruby-forum.com/t/trouble-figuring-out-select-tags/109282/3 "2007-07-13T04:55:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [July 13, 2007, 5:37am UTC](https://www.ruby-forum.com/t/trouble-figuring-out-select-tags/109282/4 "2007-07-13T05:37:55Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [July 13, 2007, 5:45am UTC](https://www.ruby-forum.com/t/trouble-figuring-out-select-tags/109282/5 "2007-07-13T05:45:04Z")

</div>

On 7/13/07, Sean C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

Please do disregard those 🙂

Cheers  
Daniel

---

<div class="post-metadata">

**Author:** ![smc7000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@smc7000](https://www.ruby-forum.com/u/smc7000)\
**Post date:** [July 13, 2007, 5:33am UTC](https://www.ruby-forum.com/t/trouble-figuring-out-select-tags/109282/6 "2007-07-13T05:33:03Z")

</div>

On 7/13/07, Sean C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
