gpt4 book ai didi

ruby-on-rails - Rails 3 iso-3166-country-select 插件如何包含空白和设置优先国家?

转载 作者:数据小太阳 更新时间:2023-10-29 08:33:49 24 4
gpt4 key购买 nike

我正在使用 ActiveAdmin(它使用 Formtastic)和用于国家/地区选择菜单的 iso-3166-country-select 插件。

我希望插件首先包含一个空白选项,以防用户忘记选择一个国家,它会得到一个验证错误。但是现在的设置方式是,澳大利亚位于列表的顶部,因此如果用户忘记设置国家/地区,澳大利亚将被设置为他们的国家/地区。

该插件有一些优先国家设置,例如澳大利亚、加拿大、英国和美国,我想更改优先国家,但我找不到他们如何将这些国家设置为优先国家的任何地方。该代码对我尝试添加 priority_countries 数组但无法使其工作有一些评论。我认为这是因为可能是 Formtastic 或 ActiveAdmin 在其他地方设置了它们。

我只是在 activeadmin 文件中有这个

f.inputs "Company Contact Details" do
f.input :address
f.input :city
f.input :state
f.input :postal_code
f.input :country
f.input :business_phone
f.input :business_phone_2
end

最佳答案

我正在使用名为 localized_country_select 的 country_select 插件的更新版本。此插件允许您包含一个空白并设置优先国家。它还执行国家代码。这是一个非常有用的插件,您可以考虑更新到这个插件以使其与 ActiveAdmin 一起使用。这是我的项目中的代码片段。

f.inputs "Place Information" do   
f.input :longitude
f.input :latitude
f.input :address
f.input :city
f.input :country,
:include_blank => 'Please choose...',
:priority_countries => ['US', 'CA', 'MX', 'GB', 'FR']
end

要安装插件,请删除之前的 country_select 插件,然后:

rails plugin install git://github.com/RainerBlessing/localized_country_select.git

插件代码可在此处获得: https://github.com/RainerBlessing/localized_country_select

有关此插件的更多信息: http://www.restafari.org/localized-country-select.html

关于ruby-on-rails - Rails 3 iso-3166-country-select 插件如何包含空白和设置优先国家?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8658799/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com