# Collection\_select default value?

**URL:** <https://www.ruby-forum.com/t/collection-select-default-value/119187>\
**Category:** Rails\
**Created:** [November 4, 2007, 6:13pm UTC](https://www.ruby-forum.com/t/collection-select-default-value/119187 "2007-11-04T18:13:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac8455/32.png) [@vanik](https://www.ruby-forum.com/u/vanik)\
**Post date:** [November 4, 2007, 6:13pm UTC](https://www.ruby-forum.com/t/collection-select-default-value/119187/1 "2007-11-04T18:13:39Z")

</div>

I’m having some confusion with collection\_select(). I am using two  
of them on my form:

\<%= collection\_select(:user, :id, @users, :id, :login) %\>  
\<%= collection\_select(:department, :id, @depts, :id, :name, {},  
:multiple=\>“multiple”) %\>

If I submit the page without selecting a department in the multiselect  
box, I will get a nil object. This is what I want.

If I submit the page without selecting a user, I do not get a nil user  
object. It is populated with the first item in the select box. This  
is not what I want. I want to detect that a user has not selected a  
name from the list.

Why is the first collection\_select() returning a value when the user  
has not selected an item?

Thx,

Gary H.

---

<div class="post-metadata">

**Author:** ![vanik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac8455/32.png) [@vanik](https://www.ruby-forum.com/u/vanik)\
**Post date:** [November 5, 2007, 10:55am UTC](https://www.ruby-forum.com/t/collection-select-default-value/119187/2 "2007-11-05T10:55:00Z")

</div>

You have two options for this:

1. \<%= collection\_select(:user, :id, @users, :id, :login,  
{:include\_blank =\> true}) %\> to show a blank option  
OR
2. \<%= collection\_select(:user, :id, @users, :id, :login, {:promt =\>  
‘Select a user’}) %\> to show a default text

Hope this helps
