你好我已经包含了给定的代码
<%= form.collection_select :country_id, available_countries, :id, :name, {}, {class: 'required'} %>
给了我以下列表::
<select class="required valid" name="order[bill_address_attributes][country_id]" id="order_bill_address_attributes_country_id">
<option value="1">Åland Islands</option>
<option value="2">Albania</option>
<option value="3">Algeria</option>
<option value="4">American Samoa</option>
<option value="5">Andorra</option>
<option value="6">Angola</option>
</select>
我需要一个像这样的列表::
<select class="required valid" name="order[bill_address_attributes][country_id]" id="order_bill_address_attributes_country_id">
<option value="1" iso = "AX">Åland Islands</option>
<option value="2" iso = "AL">Albania</option>
<option value="3" iso = "DZ">Algeria</option>
<option value="4" iso = "AD" >Andorra</option>
</select>
我使用available_countries.map(&:iso)
请指导我如何在选项标签内插入iso。
答案 0 :(得分:1)
f.select :country_id, options_for_select(@countries.map{ |c| [c.name, c.id, { 'data-currency_code' => c.currency_code }] })
答案 1 :(得分:1)
试试这个:
available_countries.map {|c| [c.name, c.id, {:'iso' => c.iso} ] }