調查simple_form源代碼是一個真正的PITA,因爲它是如此令人難以置信的抽象。但從我所看到的情況來看,這似乎是使用CountrySelect Gem時的問題。
該寶石說,你應該使用iso_codes: true
,以確保代碼被用作關鍵。我猜你必須仔細研究如何處理priority
參數或嘗試將此選項傳遞給gem。
下面是相關代碼:
def country_options_for_select(selected = nil, priority_countries = nil, use_iso_codes = false)
country_options = "".html_safe
if priority_countries
priority_countries_options = if use_iso_codes || ::CountrySelect.use_iso_codes
priority_countries.map do |code|
[
::CountrySelect::COUNTRIES[code],
code
]
end
else
priority_countries
end
country_options += options_for_select(priority_countries_options, selected)
country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n".html_safe
#
# prevents selected from being included
# twice in the HTML which causes
# some browsers to select the second
# selected option (not priority)
# which makes it harder to select an
# alternative priority country
#
selected = nil if priority_countries.include?(selected)
end
values = if use_iso_codes || ::CountrySelect.use_iso_codes
::CountrySelect::ISO_COUNTRIES_FOR_SELECT
else
::CountrySelect::COUNTRIES_FOR_SELECT
end
return country_options + options_for_select(values.sort, selected)
end
不得不升級我的寶石經測試,使用小寫僅在我的選擇行上包含iso_codes:true。通過simple_form工作。 – map7