# Odd button behaviour

**URL:** <https://www.ruby-forum.com/t/odd-button-behaviour/92380>\
**Category:** Rails\
**Created:** [April 18, 2007, 9:32pm UTC](https://www.ruby-forum.com/t/odd-button-behaviour/92380 "2007-04-18T21:32:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![seeah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@seeah](https://www.ruby-forum.com/u/seeah)\
**Post date:** [April 18, 2007, 9:32pm UTC](https://www.ruby-forum.com/t/odd-button-behaviour/92380/1 "2007-04-18T21:32:54Z")

</div>

Working on an odd one here. I’ve got a simple scaffold that for some  
reason doesn’t catch the correct data back on boolean fields. That’s  
to say that every time I load the page, every single true/false menu  
option is set to false.

The scaffold generated the following for the boolean fields in the  
\_form.rhtml file:

Active  
FalseTrue

It’s completely inert html with no possibility of pulling in the  
current field value so it makes sense that it’s not truly interactive.

If I select True, it does get correctly passed back and written to  
the database, but if I don’t touch it, the false value gets written  
to the database. So I thought that it would be more intelligent if  
these options were presented as radio buttons and see if I couldn’t  
replace the html with some code.

I’ve tried a number of variations, and according to the documentation  
at [http://edgedocs.planetargon.org/](http://edgedocs.planetargon.org/) I should do this:  
radio\_button(object\_name, method, tag\_value, options = {})  
Returns a radio button tag for accessing a specified attribute  
(identified by method) on an object assigned to the template  
(identified by object). If the current value of method is tag\_value  
the radio button will be checked. Additional options on the input tag  
can be passed as a hash with options. Example (call, result). Imagine  
that @post.category returns “rails”:

radio\_button(“post”, “category”, “rails”)  
radio\_button(“post”, “category”, “java”)

However, when I supply

\<%= radio\_button(“consultant”,“active”,“True”) %\>  
\<%= radio\_button(“consultant”,“active”,“False”) %\>

I get:

which doesn’t match the documentation. And more importantly, it  
doesn’t work 🙂

The environment is:

- ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.9.1]
- Rails 1.2.3

Can anyone shed some light on this behaviour?

Erik

---

<div class="post-metadata">

**Author:** ![seeah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@seeah](https://www.ruby-forum.com/u/seeah)\
**Post date:** [April 19, 2007, 5:03am UTC](https://www.ruby-forum.com/t/odd-button-behaviour/92380/2 "2007-04-19T05:03:28Z")

</div>

Erik A. wrote:

> \<%= radio\_button(“consultant”,“active”,“True”) %\>  
> \<%= radio\_button(“consultant”,“active”,“False”) %\>

Instead write

\<%= radio\_button :consultant, :active, true %\>  
\<%= radio\_button :consultant, :active, false %\>

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![seeah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@seeah](https://www.ruby-forum.com/u/seeah)\
**Post date:** [April 19, 2007, 9:25am UTC](https://www.ruby-forum.com/t/odd-button-behaviour/92380/3 "2007-04-19T09:25:04Z")

</div>

This works - many thanks for the tip. Any pointers to documentation  
that explains the why?

Cheers,

Erik  
Le 19 avr. 07 à 05:02, Mark Reginald J. a écrit :

---

<div class="post-metadata">

**Author:** ![seeah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@seeah](https://www.ruby-forum.com/u/seeah)\
**Post date:** [April 19, 2007, 10:11am UTC](https://www.ruby-forum.com/t/odd-button-behaviour/92380/4 "2007-04-19T10:11:08Z")

</div>

Erik A. wrote:

> This works - many thanks for the tip. Any pointers to documentation  
> that explains the why?
> 
> > \<%= radio\_button :consultant, :active, true %\>  
> > \<%= radio\_button :consultant, :active, false %\>

The radio\_button docs state that “If the current value of method  
is tag\_value the radio button will be checked”.

Your method returns a boolean, so the tag\_values must be boolean  
to pass an equality test. The helper automatically turns  
the boolean values into strings for the HTML.

–  
We develop, watch us RoR, in numbers too big to ignore.
