12
我正在使用Rails 2.3.8。我的代碼:在Rails中關聯標籤和單選按鈕
<%= f.radio_button :status, "draft" %>
<%= f.label :status, "Draft" %>
<%= f.radio_button :status, "published" %>
<%= f.label :status, "Published" %>
輸出:
<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>
顯然label
不與我的單選按鈕關聯正確。我想讓label
與單選按鈕id
相同。我該如何糾正?
謝謝。
我是新來的回報率,我覺得formtastic比較容易的方式來處理表單的意見。你可能想試試看:https://github.com/justinfrench/formtastic – LapinLove404 2011-02-07 13:18:10