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"开发者_如何学JAVA 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.
Try this
<%= f.radio_button :status, "draft" %>
<%= f.label :status, "Draft", :value => "draft" %>
<%= f.radio_button :status, "published" %>
<%= f.label :status, "Published", :value => "published" %>
This worked for me, where I was looping through plans:
<% @plans.each do |plan| %>
<%= radio_button_tag :plan_id, plan.id %>
<%= label_tag 'plan_id_' + plan.id.to_s, plan.name %>
<% end %>
精彩评论