# Collection\_select

**URL:** <https://www.ruby-forum.com/t/collection-select/182492>\
**Category:** Rails\
**Created:** [January 28, 2010, 10:14pm UTC](https://www.ruby-forum.com/t/collection-select/182492 "2010-01-28T22:14:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scrozier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@scrozier](https://www.ruby-forum.com/u/scrozier)\
**Post date:** [January 28, 2010, 10:14pm UTC](https://www.ruby-forum.com/t/collection-select/182492/1 "2010-01-28T22:14:34Z")

</div>

I’m rendering my form in a partial, as below:

…

\<%= f.collection\_select :color\_id, @colors, :id, :name, {:include\_blank  
=\> false, :prompt =\> ‘What color?’} %\>  
…

Now, I’m rendering this partial in both the new and edit methods of my  
controller. Everything works great, except for one caveat.

If the user deletes the color that was assigned prior, this results in  
the parent object being assigned a color ID that doesn’t exist.

It doesn’t throw up any errors, but when you go into the edit method of  
the parent controller to change the color, another color is  
automatically selected. It seems that the options for :prompt are  
ignored when the value is passed when in the edit method for example,  
even if that value no longer exists.

What I’d like for it to do is to show the prompt - even in the edit  
method - if the value doesn’t exist. Any way to do this?

Thanks in advance for any help at all.

---

<div class="post-metadata">

**Author:** ![scrozier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@scrozier](https://www.ruby-forum.com/u/scrozier)\
**Post date:** [January 29, 2010, 2:11am UTC](https://www.ruby-forum.com/t/collection-select/182492/2 "2010-01-29T02:11:51Z")

</div>

Fixed it. Turns out I was using collection\_select wrong. This works  
perfectly:

\<%= f.collection\_select :items, :color\_id, @colors, :id, :name,  
{:include\_blank  
=\> false, :prompt =\> ‘What color?’} %\>

---

<div class="post-metadata">

**Author:** ![scrozier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@scrozier](https://www.ruby-forum.com/u/scrozier)\
**Post date:** [January 29, 2010, 2:24am UTC](https://www.ruby-forum.com/t/collection-select/182492/3 "2010-01-29T02:24:21Z")

</div>

Looks like this is already known:

[http://dev.rubyonrails.org/ticket/10768](http://dev.rubyonrails.org/ticket/10768)

---

<div class="post-metadata">

**Author:** ![scrozier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@scrozier](https://www.ruby-forum.com/u/scrozier)\
**Post date:** [January 29, 2010, 2:14am UTC](https://www.ruby-forum.com/t/collection-select/182492/4 "2010-01-29T02:14:20Z")

</div>

Actually - nevermind. I thought it fixed the issue but turns out it’s  
still not working right. I was still using the collection\_select wrong,  
I believe - so at least that was fixed.
