form options selections demystified...

Hi there,

I have a form which has a variety of fields and field types. Each
field is presenting a unique challenge in understanding how the active
option is selected by default from data in the corresponding model.

In one instance, I have two radio buttons, "on" and "off." In the
controller, I load up the boolean value for the user's settings from
the model user > notifications.

In the view I have the following:

<%= radio_button :user, :notifications, 1, :onclick =>
"Field.enable('time'), Field.enable('period')" %> on
<%= radio_button :user, :notifications, 0, :onclick =>
"Field.disable('time'), Field.disable('period')" %> off

I've added :checked => checked to get a default option (so I know that
works), but what I want is for the checked option to correspond to the
state in the model :user, :notifications. How do i do this???

These form helpers I'm finding confusing for this. Thanks for the
help.

-Alex

ressister wrote:

Hi there,

I have a form which has a variety of fields and field types. Each
field is presenting a unique challenge in understanding how the active
option is selected by default from data in the corresponding model.

These form helpers I'm finding confusing for this. Thanks for the
help.

-Alex

I prefer radio_button_tag. For the third param, supply a method call to
a function in the model that returns true or false depending on whether
it should be selected or not.

jp