Easy way to build a selector for Taiwan Cities and Districts.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
bin
config
db
lib
spec
.gitignore
.rspec
.ruby-version
.travis.yml
Gemfile
Gemfile.lock
MIT-LICENSE
README.md
README_zh-TW.md
Rakefile
taiwan_districts.gemspec

README.md

TaiwanDistricts

Build Status CircleCI

正體中文

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

Special Thanks