在Rails中关联标签和单选按钮 [英] Associating label and radio button in Rails
本文介绍了在Rails中关联标签和单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Rails 2.3.8。我的代码:
<%= f.radio_button:status,draft%>
<%= f.label:status,草稿%>
<%= f.radio_button:status,published%>
<%= f.label:status,已发布%>
输出:
< input id =shop_status_draftname =shop [status]type =radiovalue =draft/>
< label for =shop_status>草稿< / label>
< input checked =checkedid =shop_status_publishedname =shop [status]type =radiovalue =published/>
< label for =shop_status>发布< / label>
很明显,标签
没有关联我的单选按钮正确。我想让标签
与单选按钮 id
相同。
<%= f.radio_button:status,draft%>
<%= f.label:status,草稿,:值=> 草稿%>
<%= f.radio_button:status,published%>
<%= f.label:status,Published,:value => 已发布%>
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.
解决方案
Try this
<%= f.radio_button :status, "draft" %>
<%= f.label :status, "Draft", :value => "draft" %>
<%= f.radio_button :status, "published" %>
<%= f.label :status, "Published", :value => "published" %>
这篇关于在Rails中关联标签和单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文