【问题标题】:Rails list countries by regionRails 按地区列出国家/地区
【发布时间】:2013-12-05 10:24:01
【问题描述】:

我有一个用户表,我想保存用户国家和地区信息。我目前有一个表格,我正在使用以下国家/地区选择 gem 来列出所有县:

<%= country_select("user", "country", [ "United Kingdom", "France", "Germany"]) %>

但这只会将国家名称保存在用户表国家列中。我想按地区分隔每个用户,但我不知道从哪里开始。我调查过

https://github.com/hexorx/countries

这个项目。但我不知道如何解决这个问题。任何帮助将不胜感激。

【问题讨论】:

标签: ruby-on-rails ruby-on-rails-3


【解决方案1】:

在国家宝石完全通过。你一定会得到答案的。

这里的代码可以帮助你

c = Country.find_country_by_name(params[:user][:country])
region = c.region
# save the user with the region 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-07
    • 2011-12-20
    • 1970-01-01
    相关资源
    最近更新 更多