Rails 怎么为 simple_form 的 collection_radio_buttons 每个选项设置不同的属性值

Jacob · November 05, 2012 · Last by fieryfish replied at December 18, 2012 · 3600 hits
<%= f.collection_radio_buttons :address_id, @addresses.map {|a| [a.id, a.name]}, :first, :last, {:item_wrapper_tag => :div, :item_wrapper_class => "option_box", :wrapper => false} %>

生成

<div class="option_box">
<input checked="checked" id="order_address_id_9" name="order[address_id]" type="radio" value="9"  >
<label class="collection_radio_buttons" for="order_address_id_9">张三丰, 21313212312, 宁夏回族自治区 银川市 市辖区 , 213123
</label>
</div>

我现在想在 input 里面加一个额外的参数,这个参数每个选项都不同:

<input checked="checked" id="order_address_id_9" name="order[address_id]" type="radio" value="9"  **class="address_9"** />
<input checked="checked" id="order_address_id_10" name="order[address_id]" type="radio" value="9"  **class="address_10"** />

该这么写?

你是说自定义属性吗,就像 id 属性一样,自己定义一个 iddd 之类的属性,是这个意思吗?

是的,这个自定义属性需要依靠 collection 的规则,不是相同的

你是银川的么?

You need to Sign in before reply, if you don't have an account, please Sign up first.