Forum: Ruby on Rails Select and options_for_select trouble

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2fba0881396c95771fd22ff200c16294?d=identicon&s=25 Petros Amiridis (amiridis)
on 2007-05-04 10:34
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:

<p>
<label for="command_status">Status</label><br/>
<%= select('command', 'status',
options_for_select({'Pending' => 1, 'Completed' => 2, 'Canceled' => 3}))
%>
</p>

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

Thank you,
Petros
2fba0881396c95771fd22ff200c16294?d=identicon&s=25 Petros Amiridis (amiridis)
on 2007-05-04 15:20
Petros Amiridis wrote:
> <p>
> <label for="command_status">Status</label><br/>
> <%= select('command', 'status',
> options_for_select({'Pending' => 1, 'Completed' => 2, 'Canceled' => 3}))
> %>
> </p>

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
This topic is locked and can not be replied to.