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
On Nov 4, 5:13 pm, Gary Huntress
<ghuntr...-Wuw85uim5zDR7s880joybQ@public.gmane.org>
wrote:> I''m having some confusion withcollection_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 firstcollection_select() returning a value when the user
> has not selected an item?
>
> Thx,
>
> Gary H.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---