ruby - 国家/地区的 Ruby 数组条带连接接受?
问题描述
有没有什么地方可以把这个国家列表作为一个红宝石数组?
我需要它用于表单字段,例如
<%= f.label :country %><br>
<%= f.select :country, ['Australia', 'Austria', 'etc', 'etc'], required: true %>
我可以手动输入(我可能会这样做),但只是想检查一下我没有重新发明轮子(它可能已经存在于某个地方)
解决方案
好的,就是这样。请注意,墨西哥的注释掉了
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'
]
另请注意,country
Stripe 函数的参数通常需要两个字符的字母数字国家代码(例如“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
推荐阅读
- c# - 收到一条错误消息,说明 StringContent 中缺少参数,但它存在?
- javascript - 递归地跟踪具有最终值的嵌套对象键
- typescript - 扩展接口以包含日期类型
- android - Andorid中的图像数据解密错误
- spring - 在我的 Spring Boot 项目中保护 REST API 的 spring 安全实现
- python - 用loc计算timedelta?
- image - 将一个音频文件和一个图像文件合并,用 ffmpeg 创建一个视频
- javascript - GeoJSON 源的 OpenLayers 过滤器
- javascript - 初学者:那么我在下面的代码中做错了什么?(有吊装的东西??)
- javascript - 数据表日期范围过滤器无法正常工作