Forum: Ruby on Rails A question about select_tag

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.
7fbd0e99b27064b14793f028022974e5?d=identicon&s=25 Zhao Yi (youhaodeyi)
on 2008-12-25 09:11
I use select_tag to create a dropdown selection box:

select_tag "people", "<option>David</option><option>Mike</option>"

but I want the option value is from a variable in a controller. How can
I do this?
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2008-12-25 17:01
(Received via mailing list)
On Thu, Dec 25, 2008 at 12:11 AM, Zhao Yi
<rails-mailing-list@andreas-s.net> wrote:
>
> I use select_tag to create a dropdown selection box:
>
> select_tag "people", "<option>David</option><option>Mike</option>"
>
> but I want the option value is from a variable in a controller. How can
> I do this?

See the docs for `options_from_collection_for_select`.

HTH,
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
5eb57ea1f36182bdd64e5601a73262e6?d=identicon&s=25 Nellboy (Guest)
on 2008-12-25 19:34
(Received via mailing list)
try:

select_tag 'people', options_for_select(@names)

On Dec 25, 4:00 pm, "Hassan Schroeder" <hassan.schroe...@gmail.com>
This topic is locked and can not be replied to.