Edit method: Populating select box values

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

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

<%= 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

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