Radio buttons with boolean field in database

I create form (i want to create the interface for inserting in the table
users).
Table users has a boolean field, get_newsletter (=if the user want
newsletter).

In *.rhtml, I have

want newsletter <%= radio_button( “user”, “get_newsletter”, “1”,
:checked => ‘checked’ ) %>
dont want newsletter <%= radio_button( “auto”, “get_newsletter”, “0” )
%>

But it’s not working. If the .save method fails (because of other
fields), my radio group is not set correctly (other fields are correctly
set).

Can someone tell me how to work with radio groups and boolean fields in
database?
Thank you

RoR 1.1, mysql 5

Yeah I’m having the same issue. Did you ever get it to work properly?

Mark wrote:

I create form (i want to create the interface for inserting in the table
users).
Table users has a boolean field, get_newsletter (=if the user want
newsletter).

In *.rhtml, I have

want newsletter <%= radio_button( “user”, “get_newsletter”, “1”,
:checked => ‘checked’ ) %>
dont want newsletter <%= radio_button( “auto”, “get_newsletter”, “0” )
%>

Mark wrote:

Can someone tell me how to work with radio groups and boolean fields in
database?

Not what you’re going to want to hear, but radio buttons don’t work with
boolean fields. You can change the type of field to integer and it’ll
work great, but not with boolean.

So far as I can tell, the only field type that works with boolean is the
check box.

—Michael

Hmm, I’m using TinyInt as my MySQL field, and it still doesn’t seem to
be working.

Michael S. wrote:

Mark wrote:

Can someone tell me how to work with radio groups and boolean fields in
database?

Not what you’re going to want to hear, but radio buttons don’t work with
boolean fields. You can change the type of field to integer and it’ll
work great, but not with boolean.

So far as I can tell, the only field type that works with boolean is the
check box.

—Michael

Mark wrote:

Can someone tell me how to work with radio groups and boolean fields in
database?
Thank you

RoR 1.1, mysql 5

Should be simple, use true and false, like any boolean value should. I
have this work in a production application right now, although it runs
on edge, not 1.1

<%= radio_button ‘foo’, ‘enabled’, false %>
<%= radio_button ‘foo’, ‘enabled’, true %>

ActiveRecord then converts the true or false to a 0 or 1 for you, if
your database requires it.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs