Odd button behaviour

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/ 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 :slight_smile:

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

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.

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 :

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.