# Help with collection\_select

**URL:** <https://www.ruby-forum.com/t/help-with-collection-select/140468>\
**Category:** Rails\
**Created:** [June 14, 2008, 3:10pm UTC](https://www.ruby-forum.com/t/help-with-collection-select/140468 "2008-06-14T15:10:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ANSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@ANSS](https://www.ruby-forum.com/u/ANSS)\
**Post date:** [June 14, 2008, 3:10pm UTC](https://www.ruby-forum.com/t/help-with-collection-select/140468/1 "2008-06-14T15:10:45Z")

</div>

Hi,  
I have a table called ‘users’, there is a field called ‘username’ and  
another field called ‘mobile\_number’ (among other fields).  
In my application the user can send SMS message and can choose between  
his/her username and mobile number as the sender id. Both of them are of  
course stored in the users table. Also there is a third option which is  
the  
domain name of the website, it should be a static value (not retrieved  
from  
the database)

I need to create a drop down select menu that enables the user to do  
that,  
I’ve spent a lot of time with collection\_select but couldn’t get it to  
work.  
Anyone can help me with this?

Regards

---

<div class="post-metadata">

**Author:** ![ANSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@ANSS](https://www.ruby-forum.com/u/ANSS)\
**Post date:** [June 14, 2008, 3:32pm UTC](https://www.ruby-forum.com/t/help-with-collection-select/140468/2 "2008-06-14T15:32:27Z")

</div>

It worked now. I’ve read somewhere that I have to use collection\_select  
if I  
want to retrieve data from the DB so I was struggling with  
collection\_select, now I did it with ‘select’, I stored the data in the  
controller in an array like:

def new  
@user = User.find(logged\_in\_user)  
@sending\_options =[@user.username, @user.mobile\_number,  
‘[DOMAIN.COM](http://DOMAIN.COM)’]

end

in the veiw:

\<%= f.select :sender, @sending\_options, :class =\> ‘fieldcell’ %\>

That’s it 🙂

2008/6/14 AN@S [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I’ve spent a lot of time with collection\_select but couldn’t get it to work.  
> Anyone can help me with this?
> 
> Regards

–  
Anas Marrawi  
Visit me at: [www.anasonline.net](http://www.anasonline.net)

If you want to send me encrypted emails. My public key: pub:13427489:17
