# Radio buttons refusing to load checked

**URL:** <https://www.ruby-forum.com/t/radio-buttons-refusing-to-load-checked/102078>\
**Category:** Rails\
**Created:** [August 10, 2006, 12:41pm UTC](https://www.ruby-forum.com/t/radio-buttons-refusing-to-load-checked/102078 "2006-08-10T12:41:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bex3000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bb73d2/32.png) [@bex3000](https://www.ruby-forum.com/u/bex3000)\
**Post date:** [August 10, 2006, 12:41pm UTC](https://www.ruby-forum.com/t/radio-buttons-refusing-to-load-checked/102078/1 "2006-08-10T12:41:39Z")

</div>

Hi,

Having big problems with radio buttons that just don’t make sense:

\<%= radio\_button “events”, “impact\_type”, true %\> Positive  
\<%= radio\_button “events”, “impact\_type”, false %\> Negative

This should create two radio buttons with the first one checked by  
default, right? Cos it doesn’t ☹

Any ideas would be great,  
Thanks,  
Bex

---

<div class="post-metadata">

**Author:** ![bex3000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bb73d2/32.png) [@bex3000](https://www.ruby-forum.com/u/bex3000)\
**Post date:** [August 11, 2006, 12:28am UTC](https://www.ruby-forum.com/t/radio-buttons-refusing-to-load-checked/102078/2 "2006-08-11T00:28:46Z")

</div>

Becky F. wrote:

> Hi,
> 
> Having big problems with radio buttons that just don’t make sense:
> 
> \<%= radio\_button “events”, “impact\_type”, true %\> Positive  
> \<%= radio\_button “events”, “impact\_type”, false %\> Negative
> 
> This should create two radio buttons with the first one checked by  
> default, right? Cos it doesn’t ☹
> 
> Any ideas would be great,  
> Thanks,  
> Bex

try 1 and 0 instead of true and false

calling the boolean field directly gives you a 1 or 0. You only get the  
true/false if you call the method with a ?

So the form helper tries to match the values of the option buttons to  
@events.impact\_type, which gives a 1 or 0.

---

<div class="post-metadata">

**Author:** ![bex3000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bb73d2/32.png) [@bex3000](https://www.ruby-forum.com/u/bex3000)\
**Post date:** [August 15, 2006, 2:13pm UTC](https://www.ruby-forum.com/t/radio-buttons-refusing-to-load-checked/102078/3 "2006-08-15T14:13:54Z")

</div>

Hi Becky,

Try this instead:

\<%= radio\_button “events”, “impact\_type”, true, :checked =\> true %\>

The API for  
radio\_button[http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M000395](http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M000395)indicates  
the 3rd param as the value  
of the radio button, not whether the checked attribute it set or not.

But I guess you might have mistaken it with the API for  
radio\_button\_tag[http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M000501](http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M000501)  
.

–  
choonkeat

- [http://blog.yanime.org/](http://blog.yanime.org/)
- [http://www.rssfwd.com/](http://www.rssfwd.com/)

---

<div class="post-metadata">

**Author:** ![bex3000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bb73d2/32.png) [@bex3000](https://www.ruby-forum.com/u/bex3000)\
**Post date:** [August 18, 2006, 7:12pm UTC](https://www.ruby-forum.com/t/radio-buttons-refusing-to-load-checked/102078/4 "2006-08-18T19:12:05Z")

</div>

Becky F. wrote:

> Hi,
> 
> Having big problems with radio buttons that just don’t make sense:
> 
> \<%= radio\_button “events”, “impact\_type”, true %\> Positive  
> \<%= radio\_button “events”, “impact\_type”, false %\> Negative
> 
> This should create two radio buttons with the first one checked by  
> default, right? Cos it doesn’t ☹
> 
> Any ideas would be great,  
> Thanks,  
> Bex

Hi,

Try using

\<%= radio\_button “events”, “impact\_type”, “true”, {:checked =\>  
‘checked’} %\>

hope this helps

-cd
