首页 > 解决方案 > 国家/地区的 Ruby 数组条带连接接受?

问题描述

有没有什么地方可以把这个国家列表作为一个红宝石数组?

在此处输入图像描述

我需要它用于表单字段,例如

<%= f.label :country %><br>
<%= f.select :country, ['Australia', 'Austria', 'etc', 'etc'], required: true %>

我可以手动输入(我可能会这样做),但只是想检查一下我没有重新发明轮子(它可能已经存在于某个地方)

标签: rubystripe-payments

解决方案


好的,就是这样。请注意,墨西哥的注释掉了

stripe_connect_countries = [
  'Australia', 
  'Austria',
  'Belgium',
  'Bulgaria',
  'Canada',
  'Cyprus',
  'Czech Republic',
  'Denmark',
  'Estonia',
  'Finland',
  'France',
  'Germany',
  'Greece',
  'Hong Kong SAR China',
  'Hungary',
  'Ireland',
  'Italy',
  'Japan',
  'Latvia',
  'Lithuania',
  'Luxembourg',
  'Malta',
  # 'Mexico',     
  'Netherlands',
  'New Zealand',
  'Norway',
  'Poland',
  'Portugal',
  'Romania',
  'Singapore',
  'Slovakia',
  'Slovenia',
  'Spain',
  'Sweden',
  'Switzerland',
  'United Kingdom',
  'United States'
]

另请注意,countryStripe 函数的参数通常需要两个字符的字母数字国家代码(例如“US”、“EG”或“GB”)。是国家代码的完整列表

由于事实证明这些国家/地区是用户友好的,但 Stripe 函数需要 2 个字符代码,这里有一个有用的函数提供哈希映射国家到代码(再次,墨西哥注释掉)

def stripe_connect_countries

  {'Australia': 'AU', 
    'Austria': 'AT',
    'Belgium': 'BE',
    'Bulgaria': 'BG',
    'Canada': 'CA',
    'Cyprus': 'CY',
    'Czech Republic': 'CZ',
    'Denmark': 'DK',
    'Estonia': 'EE',
    'Finland': 'FI',
    'France': 'FR',
    'Germany': 'DE',
    'Greece': 'GR',
    'Hong Kong SAR China': 'HK',
    'Hungary': 'HU',
    'Ireland': 'IE',
    'Italy': 'IT',
    'Japan': 'JP',
    'Latvia': 'LV',
    'Lithuania': 'LT',
    'Luxembourg': 'LU',
    'Malta': 'MT',
    # 'Mexico': 'MX',     
    'Netherlands': 'NL',
    'New Zealand': 'NZ',
    'Norway': 'NO',
    'Poland': 'PL',
    'Portugal': 'PT',
    'Romania': 'RO',
    'Singapore': 'SG',
    'Slovakia': 'SK',
    'Slovenia': 'SI',
    'Spain': 'ES',
    'Sweden': 'SE',
    'Switzerland': 'CH',
    'United Kingdom': 'GB',
    'United States': 'US'
  }

end

推荐阅读