# Edit method: Populating select box values

**URL:** <https://www.ruby-forum.com/t/edit-method-populating-select-box-values/105657>\
**Category:** Rails\
**Created:** [June 1, 2007, 4:02am UTC](https://www.ruby-forum.com/t/edit-method-populating-select-box-values/105657 "2007-06-01T04:02:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [June 1, 2007, 4:02am UTC](https://www.ruby-forum.com/t/edit-method-populating-select-box-values/105657/1 "2007-06-01T04:02:27Z")

</div>

I have an employees table that contains fields that are boolean to  
control information formatting. The ‘new’ method sets the value of the  
select box to the default value contained in the table. During the  
‘edit’ method these values are the table defaults not the values  
contained in the table. How can I change the following excerpt of  
\_form.rhtml to use the table values contained in the record? Note:  
This is the code generated by the scaffold controller.

Publish Address FalseTrue

Thanks in Advance

reback

---

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [June 1, 2007, 2:39pm UTC](https://www.ruby-forum.com/t/edit-method-populating-select-box-values/105657/2 "2007-06-01T14:39:42Z")

</div>

As it stands, that is just static html. It’s not picking a default from  
anywhere. You need to use the select method as embedded ruby and add the  
:selected option. It will look something like this:

\<%= select ‘employee’, ‘pubadd’, [[“true”, “true”] , [“false”,  
“false”]], :selected =\> @employee.pubadd ? @employee.pubadd : “false” %\>

I havent actually tried that but a bit of fiddling should get it doing  
what you want.

steve

---

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [June 1, 2007, 7:02pm UTC](https://www.ruby-forum.com/t/edit-method-populating-select-box-values/105657/3 "2007-06-01T19:02:04Z")

</div>

> \<%= select ‘employee’, ‘pubadd’, [[“true”, “true”] , [“false”,  
> “false”]], :selected =\> @employee.pubadd ? @employee.pubadd : “false” %\>

Actually it looks like you don’t need the :selected option, rails does  
it anyway if @employee is set.

steve

---

<div class="post-metadata">

**Author:** ![reback](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5ac83/32.png) [@reback](https://www.ruby-forum.com/u/reback)\
**Post date:** [June 1, 2007, 9:07pm UTC](https://www.ruby-forum.com/t/edit-method-populating-select-box-values/105657/4 "2007-06-01T21:07:31Z")

</div>

Thanks Steve,

That works great!

I knew that the html generated from the scaffolding was static. However  
I am surprised that the rails generators are not better at handling  
boolean type data fields.

Richard
