Forum: Ruby on Rails the selected element in a list.

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
P. P. (Guest)
on 2007-01-29 18:06
 I'm trying to populate a drop-down list with objects and to set the
selected object.

<%= select_tag 'list',
lamenu.menuelement_id.to_s) %>

lamenu(it has properties "name","id" ) is an element from a list

the output in html my list looks like

<select id="list" name="list"
<option value="18">colour</option>
<option value="19">company</option>
<option value="20">country</option>
<option value="21">county</option>
The problem is that i don't have the specified
element(lamenu.menuelement_id.to_s) in the list selected at the view.

  I look in the html ant there's no <option> with the selected atribute.
  For testing I printed lamenu.menuelement_id.to_s near the select box,
if i put that value explicitly in options_from_collection_for_select

<%= select_tag 'list',
options_from_collection_for_select(@menulist,"id","name", 20) %> , then
my selected element will be the one with the id 20 and not the first one
in the list.
   There's something missing but i don't kow what..
P. P. (Guest)
on 2007-01-29 18:15
 :) horray, it worked..
  i had to put amenu.menuelement_id.to_i for this to work. In my table
menuelement_id is an int(11), I think it's odd to convert it again to
This topic is locked and can not be replied to.