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.
gem 'taiwan_districts', :git => 'https://github.com/bugtender/TaiwanDistricts'
//= require 'jquery'
//= require 'taiwan_districts/jquery.taiwan_districts'
mount TaiwanDistricts::Engine => '/taiwan_districts'
Add below code to your ERB
<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>
<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.
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
.
Add TravisCI and auto gem build.
It's works. And add some test.
MIT