Forum: Ruby on Rails Radio Button Defailt Value?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Bob B. (Guest)
on 2006-03-22 02: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?
Robert MannI (Guest)
on 2006-03-22 02:45
(Received via mailing list)
In your controller, do

@foo.bar_id = 3

or = Bar.find(3)
Bob B. (Guest)
on 2006-03-22 02:59
Robert MannI wrote:
> In your controller, do
> @foo.bar_id = 3
> or
> = Bar.find(3)

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