2016-09-22 51 views
0

你好我已經包含給定的代碼如何插入在軌ISO裏面的選項標籤

<%= 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> 

我拿起iso與available_countries.map(&:iso)

請指導我如何在選項標籤內插入iso。

回答

1
f.select :country_id, options_for_select(@countries.map{ |c| [c.name, c.id, { 'data-currency_code' => c.currency_code }] }) 
1

試試這個:

available_countries.map {|c| [c.name, c.id, {:'iso' => c.iso} ] }