[Rails] Re: Can't get select helper to populate dropdown w/default v
Peter Jagielski
pjagielski at gmail.com
Sun Jan 1 18:12:17 GMT 2006
Nick,
Here's the hash that defines the contents of the dropdown:
YESNO = { "No" => "0",
"Yes" => "1" }
In other words, the user sees options for "Yes" and "No, and either 0 or
1 are stored in the table's field. In this case, the user can specify
whether or not they are an administrator.
Here's my select helper code:
<%= select 'user', 'administrator', User::YESNO.sort, :include_blank =>
TRUE %>
I tried all manner of including :selected => ??? and it's never worked.
Now, I have found the following workaround, which solves the problem by
using Rails' options_for_select helper:
<p><label for="user_administrator">Administrator</label><br/>
<select id="user_administrator" name="user[administrator]">
<option value=""></option>
<%= options_for_select User::YESNO.sort, @user.administrator.to_s %>
</select></p>
But going back to the original question, shouldn't the basic select
helper be able to handle this?
--
Posted via http://www.ruby-forum.com/.
More information about the Rails
mailing list