TaiwanDistricts
Easy way to build a selector for Taiwan Cities and Districts.
This gem is base on china_city and TaiwanCity.
Support Rails 4.2 and upper version.
Installation
In gemfile
gem 'taiwan_districts', :git => 'https://github.com/bugtender/TaiwanDistricts'
In app/assets/javascripts/application.js
//= require 'jquery'
//= require 'taiwan_districts/jquery.taiwan_districts'
In config/routes.rb
mount TaiwanDistricts::Engine => '/taiwan_districts'
Usage
Add below code to your ERB
Traditional-Chinese
<div class='rails-helper city-group'>
<%= select_tag :city,
options_for_select( TaiwanDistricts.list(lang='zhtw') ),
prompt: '--縣市--',
class: ['city-select', 'city-city'],
lang: 'zhtw' %>
<%= select_tag :district,
nil,
prompt: '--鄉鎮市區--',
class: ['city-select', 'city-district'] %>
</div>
English
<div class='rails-helper city-group'>
<%= select_tag :city,
options_for_select( TaiwanDistricts.list(lang='en') ),
prompt: '--Cities--',
class: ['city-select', 'city-city'],
lang: 'en' %>
<%= select_tag :district,
nil,
prompt: '--Districts--',
class: ['city-select', 'city-district'] %>
</div>
all selector need city-select
class. and under the class='city-group'
DOM.
Origin districts data
In db/districts.json
. If you want to remove some districts that useless. You can fork this gem and remove the data.
The code rule of the city is custom number
+ 000
, and the district is city custom code
+ zipcode
.
Changelog
version 0.1.2
Add TravisCI and auto gem build.
version 0.1.0
It's works. And add some test.
License
MIT