views:

40

answers:

2

Hello, I have a Category model with two booleans, article_cat? and profile_cat?. I want to be able to create a new Category with a form that lists these two using radio buttons. If one radio button is marked, the other one is unmarked. It should send a true value to the create method of the one that is checked and create a new category where either article_cat or profile_cat is true. The Rails API for radio buttons does not make sense to me. Here is what I have, and it is breaking badly:

<%= f.radio_button "category", "article_cat", true %>Article <%= f.radio_button "category", "profile_cat", true %>Profile

I honestly do not know what I am doing up there. I am just experimenting.

A: 

But you don't really need two fields for this you could just use one:

<%= f.radio_button :article_cat, true %><%= f.label :article_cat %><br />
<%= f.radio_button :article_cat, false %><%= f.label :article_cat %><br />

Then it's article_cat if article_cat is true, otherwise it's profile_cat. Also you might need to set the default value for your boolean in the migration:

add_column :categories, :article_cat, :boolean, :default => true
jordinl
A: 

Hello, I am going to add a comments_cat boolean later to categorize the comments. Is there anyway to make a choice of three radio buttons. The one selected sets the other values to false? Right now, the buttons are all automatically selected.

Kelp