# Update collection\_select

**URL:** <https://www.ruby-forum.com/t/update-collection-select/172744>\
**Category:** Rails\
**Created:** [July 27, 2009, 11:41am UTC](https://www.ruby-forum.com/t/update-collection-select/172744 "2009-07-27T11:41:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![coldie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coldie](https://www.ruby-forum.com/u/coldie)\
**Post date:** [July 27, 2009, 11:41am UTC](https://www.ruby-forum.com/t/update-collection-select/172744/1 "2009-07-27T11:41:15Z")

</div>

Hi there,

I’m storing serveral values in my database through collection\_select.  
Saving the value works fine but getting the saved value by using the  
update-form and setting it as “default-selected” doesn’t work.

I tried :selected and :include\_black till now… but nothing works.

Can anyone help me?

---

<div class="post-metadata">

**Author:** ![coldie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coldie](https://www.ruby-forum.com/u/coldie)\
**Post date:** [July 27, 2009, 12:53pm UTC](https://www.ruby-forum.com/t/update-collection-select/172744/2 "2009-07-27T12:53:38Z")

</div>

On Jul 27, 5:41 am, Hans H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi there,
> 
> I’m storing serveral values in my database through collection\_select.  
> Saving the value works fine but getting the saved value by using the  
> update-form and setting it as “default-selected” doesn’t work.
> 
> I tried :selected and :include\_black till now… but nothing works.

A classic is the selected values being \_if fields (ie integers) but  
the choices being strings (and of course no 1 != “1”)

Fred

---

<div class="post-metadata">

**Author:** ![coldie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coldie](https://www.ruby-forum.com/u/coldie)\
**Post date:** [July 27, 2009, 4:41pm UTC](https://www.ruby-forum.com/t/update-collection-select/172744/3 "2009-07-27T16:41:20Z")

</div>

On Jul 27, 8:26 am, Hans H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hmmm … I can’t get this.  
> I declared my choices as strings, but i don’ know how to set a  
> DEFAULT-STRING…  
> something like
> 
> \<%= f.text\_field :subject, :value =\> @ticket.subject%\>
> 
> just for collection\_selct.

not sure collection\_select takes a similar option. Given that it reads  
the current value out of the associated model object you could just  
set it there.

Fred

---

<div class="post-metadata">

**Author:** ![coldie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coldie](https://www.ruby-forum.com/u/coldie)\
**Post date:** [July 27, 2009, 6:06pm UTC](https://www.ruby-forum.com/t/update-collection-select/172744/4 "2009-07-27T18:06:32Z")

</div>

can anyone help me?

---

<div class="post-metadata">

**Author:** ![coldie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coldie](https://www.ruby-forum.com/u/coldie)\
**Post date:** [July 27, 2009, 2:26pm UTC](https://www.ruby-forum.com/t/update-collection-select/172744/5 "2009-07-27T14:26:46Z")

</div>

Hmmm … I can’t get this.  
I declared my choices as strings, but i don’ know how to set a  
DEFAULT-STRING…  
something like

\<%= f.text\_field :subject, :value =\> @ticket.subject%\>

just for collection\_selct.

Thx

Frederick C. wrote:

> On Jul 27, 5:41ï¿½am, Hans H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Hi there,
> > 
> > I’m storing serveral values in my database through collection\_select.  
> > Saving the value works fine but getting the saved value by using the  
> > update-form and setting it as “default-selected” doesn’t work.
> > 
> > I tried :selected and :include\_black till now… but nothing works.
> 
> A classic is the selected values being \_if fields (ie integers) but  
> the choices being strings (and of course no 1 != “1”)
> 
> Fred

---

<div class="post-metadata">

**Author:** ![coldie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coldie](https://www.ruby-forum.com/u/coldie)\
**Post date:** [July 28, 2009, 7:21pm UTC](https://www.ruby-forum.com/t/update-collection-select/172744/6 "2009-07-28T19:21:02Z")

</div>

I understand you as wanting to have a default selection. If that’s  
correct then I would look into the options\_for\_select helper. It  
allows you to set a selected tag. Just make sure the selected object  
matches the type in your collection. Collection\_select only selects  
the value if it was previously saved to the database.

On Jul 27, 12:06 pm, Hans H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
