Forum: Ruby on Rails select_tag selected value?

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.
8e7e5b934fcbcdfb475072685755457f?d=identicon&s=25 Taylor Strait (Guest)
on 2007-03-30 08:59
Situation:
Administrative control panel which lists users and allows mass updates
of attributes from a single screen.

My code:
<%= select_tag("person[#{person.id}][role]", '<option>user</option>
<option>admin</option>', options = {:selected => person.role}) %>

Rendered HTML:
<select id="person[5][role]" name="person[5][role]" selected="admin">
  <option>user</option>
  <option>admin</option>
</select>

Problem:
"admin" isn't selected when it should be!  all people have "user"
selected regardless of role defined in the DB.  Any ideas?
8da797a926b3eb9e2666a4bfe0bdd71d?d=identicon&s=25 Jindong Yang (yangr)
on 2007-04-04 08:31
there's something you perhaps need!
http://www.ruby-forum.com/topic/98281#208304
This topic is locked and can not be replied to.