Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Associating label and radio button in Rails

I'm using Rails 2.3.8. My code:

<%= f.radio_button :status, "draft" %>
<%= f.label :status, "Draft" %>
<%= f.radio_button :status, "published" %>
<%= f.label :status, "Published" %>

Output:

<input id="shop_status_draft" name="shop[status]" type="radio" value="draft" />
<label for="shop_status">Draft</label>
<input checked="checked" id="shop_status_published" name="shop[status]" type="radio" value="published" />
<label for="shop_status">Published</label>

Obviously the label isn't associating with my radio buttons correctly. I want to make the label same as radio button id. How can I correct that?

Thanks.

like image 537
Victor Avatar asked Feb 07 '11 12:02

Victor


1 Answers

Try this

<%= f.radio_button :status, "draft" %>
<%= f.label :status, "Draft", :value => "draft" %>
<%= f.radio_button :status, "published" %>
<%= f.label :status, "Published", :value => "published" %>
like image 61
LapinLove404 Avatar answered Nov 20 '22 15:11

LapinLove404