[Rails] Re: Can't get select helper to populate dropdown w/default v

Nick Stuart nicholas.stuart at gmail.com
Sun Jan 1 18:30:56 GMT 2006


Well thats the way I do it Peter, using the options helper that is. By
looking at the docs for the select helper, it doesn't need/have a selected
value, it should automatically pick the right one. Like I said, I usually
always use the options helper and never really had any problems with that.

-Nick

On 1/1/06, Peter Jagielski <pjagielski at gmail.com> wrote:
>
> 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/.
> _______________________________________________
> Rails mailing list
> Rails at lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060101/9e836bcb/attachment.html


More information about the Rails mailing list