如何从 country_select gem 中将国家/地区列表提取到数组中

How to extract the list of countries into an array from country_select gem

我正在尝试提取所有国家/地区名称的列表并将它们放入 country_select gem 的数组中。在表单中添加 select 字段时如何利用此 gem 非常清楚:

<%= form_for User.new, url: root_url do |f| %>
  <%= f.country_select :country_code %>
<% end %>

但是,如果我需要在表单之外使用相同的国家/地区列表怎么办?在我的例子中,我使用 X-editable-rails gem 进行内联编辑。我的 objective 是为国家属性提供内联版本。为此,我必须指定 select 列表的来源,如下所示:

<%= editable @waiter, :country, type: :select, title: 'Your country', source: ["Country_1", "Country_2", "Country_n"] %>

但是,我想不出一种方法来提取该列表并将其放入变量中。

我在这个 stack overflow answer:

中尝试了这两种建议的方法
@countries = ActionView::Helpers::FormOptionsHelper::COUNTRIES.zip(ActionView::Helpers::FormOptionsHelper::COUNTRIES)

<%= @countries = ActionView::Helpers::FormOptionsHelper::COUNTRIES %>

任何人都可以帮助实现这一目标吗?

country_select gem 具有 countries gem 作为依赖项。 gem 提供查找器和其他与国家/地区合作的有用方法。

ISO3166::Country.all_translated 可能就是您正在寻找的方法。