bugtender / TaiwanDistricts

Easy way to build a selector for Taiwan Cities and Districts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Easy way to build a selector for Taiwan Cities and Districts.

License:MIT License


Languages

Language:Ruby 81.7%Language:HTML 13.6%Language:CoffeeScript 1.7%Language:CSS 1.6%Language:JavaScript 1.4%