Select and options_for_select trouble


#1

Hi,

I am a newbie in Ruby and Rails. I am trying to create a drop down list
with fixed values but the selected option should be saved in the
database.

I have the table commands. Each command has a status which is selected
from a fixed list. The status field in the database is an integer and
can take the values 1, 2 and 3. My view should present the user a drop
down list with human readable elements that correspond to each of the
integers above. So for 1, 2 and 3 I should present the user a list with
the following words: Pending, Completed, Canceled.

Here is what I did and the result is not what I expected:

Status
<%= select('command', 'status', options_for_select({'Pending' => 1, 'Completed' => 2, 'Canceled' => 3})) %>

This makes a drop down list but the contents are the statements
themselves!! What am I doing wrong?

Thank you,
Petros


#2

Petros A. wrote:

Status
<%= select('command', 'status', options_for_select({'Pending' => 1, 'Completed' => 2, 'Canceled' => 3})) %>

Ok, I found out myself. I don’t have to use options_for_select:

<%= select(‘command’, ‘status’,
{‘Pending’ => 1, ‘Completed’ => 2, ‘Canceled’ => 3})

Thank you,
Petros