【问题标题】:Rails 3 iso-3166-country-select plugin how to include blank and set priority countries?Rails 3 iso-3166-country-select 插件如何包含空白并设置优先国家?
【发布时间】:2011-12-28 16:51:43
【问题描述】:

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

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

该插件设置了一些优先国家,例如澳大利亚、加拿大、英国和美国,我想更改优先国家,但我找不到他们如何将这些国家设置为优先的任何地方。该代码有一些 cmets 我尝试添加一个 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

【问题讨论】:

    标签: ruby-on-rails ruby formtastic activeadmin


    【解决方案1】:

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

    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 插件安装 git://github.com/RainerBlessing/localized_country_select.git

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

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

    【讨论】:

      猜你喜欢
      • 2019-07-05
      • 2021-02-21
      • 2015-02-22
      • 1970-01-01
      • 2015-05-01
      • 2013-02-23
      • 2021-12-24
      • 2012-12-16
      • 1970-01-01
      相关资源
      最近更新 更多