saberma ad8c3c0939 Merge branch 'master' of github.com:saberma/china_city | 11 years ago | |
---|---|---|
app | 11 years ago | |
bin | 11 years ago | |
config | 11 years ago | |
db | 11 years ago | |
lib | 11 years ago | |
spec | 11 years ago | |
.gitignore | 11 years ago | |
.rspec | 11 years ago | |
.travis.yml | 11 years ago | |
Gemfile | 11 years ago | |
Gemfile.lock | 11 years ago | |
MIT-LICENSE | 11 years ago | |
README.md | 11 years ago | |
Rakefile | 11 years ago | |
china_city.gemspec | 11 years ago |
这是一个基于 Rails Engine 开发的插件,为 Rails 项目增加省市区三级(或者省市 二级)选择框,可用于实现收货地址等信息的录入。
gem 'china_city'
//= require 'jquery'
//= require 'china_city/jquery.china_city'
mount ChinaCity::Engine => '/china_city' if defined?(ChinaCity)
在页面中加入选择框,示例代码使用 slim 格式
.city-group
select.city-select
option --省份--
= options_for_select(ChinaCity.list)
select.city-select
option --城市--
select.city-select
option --地区--
请留意:所有选择框都要有 city-select
class,并都包含于 class='city-group' 的 DOM 元素之下。
选择后的值为国家地区编码,如深圳市的为 440300
,可通过调用 ChinaCity.get('440300')
将编码转化为城市名称。
git clone git@github.com:saberma/china_city.git
cd china_city
cd test/dummy
rails server # http://localhost:3000/china_city