Forum: Ruby on Rails Radio Button Defailt 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.
7238038e32eb30a16098833e3d61cb19?d=identicon&s=25 Bob Boyken (bboyken)
on 2006-03-22 01:25
I have:

<%= radio_button 'foo', 'bar_id', '1' %>
<%= radio_button 'foo', 'bar_id', '2' %>
<%= radio_button 'foo', 'bar_id', '3' %>

I would like to have option #3 be selected if foo.bar_id is nil. Is
there a way to do that?
9618e8fca8d72bf01814276c53c2568c?d=identicon&s=25 Robert MannI (Guest)
on 2006-03-22 01:45
(Received via mailing list)
In your controller, do

@foo.bar_id = 3

or

@foo.bar = Bar.find(3)
7238038e32eb30a16098833e3d61cb19?d=identicon&s=25 Bob Boyken (bboyken)
on 2006-03-22 01:59
Robert MannI wrote:
> In your controller, do
>
> @foo.bar_id = 3
>
> or
>
> @foo.bar = Bar.find(3)

Awesome, thanks!  I tried it and it works great.
This topic is locked and can not be replied to.