# Form options selections demystified

**URL:** <https://www.ruby-forum.com/t/form-options-selections-demystified/130072>\
**Category:** Rails\
**Created:** [February 25, 2008, 6:23am UTC](https://www.ruby-forum.com/t/form-options-selections-demystified/130072 "2008-02-25T06:23:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ressister](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@ressister](https://www.ruby-forum.com/u/ressister)\
**Post date:** [February 25, 2008, 6:23am UTC](https://www.ruby-forum.com/t/form-options-selections-demystified/130072/1 "2008-02-25T06:23:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ressister](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@ressister](https://www.ruby-forum.com/u/ressister)\
**Post date:** [February 25, 2008, 8:44am UTC](https://www.ruby-forum.com/t/form-options-selections-demystified/130072/2 "2008-02-25T08:44:29Z")

</div>

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
