Nessuna descrizione

ANX c402d31c3b fix: get_info_from_address address & post_code 6 anni fa
app faf10bc66b 修改為臺灣地區資料 10 anni fa
bin ac02c77b22 change china_city to taiwan_city 10 anni fa
config ac02c77b22 change china_city to taiwan_city 10 anni fa
db e0bd97a80d fix: 臺to台 & add: method get_info_from_address & add: 新竹市/嘉義市 6 anni fa
gemfiles 70292133a3 fix json format 10 anni fa
lib c402d31c3b fix: get_info_from_address address & post_code 6 anni fa
spec e0bd97a80d fix: 臺to台 & add: method get_info_from_address & add: 新竹市/嘉義市 6 anni fa
.gitignore 21230b97bd init. 11 anni fa
.rspec 8cc5a049e2 config rspec. 11 anni fa
.travis.yml 6832f25df0 use j6. 11 anni fa
Appraisals 9e7898be25 add appraisals config: support rails3.1, 3.2, and 4.0 11 anni fa
Gemfile 094ff904fe little fix 10 anni fa
Gemfile.lock 094ff904fe little fix 10 anni fa
MIT-LICENSE 8e4256923e add MIT licentse to gemspec. 11 anni fa
README.md b8499a67c7 補上取用城市名稱的方法說明 8 anni fa
Rakefile ac02c77b22 change china_city to taiwan_city 10 anni fa
taiwan_city.gemspec 27d5ffceec fix gemspec dependency 10 anni fa

README.md

TaiwanCity 台灣縣市下拉列表

此rubygem 程式結構以china_city做參考,保留大部分原文說明。只在不同處做修改

支持 Rails3.1, Rails3.2, Rails4.0。

请留意,Rails3.1 与 Ruby2.0 不兼容,sprockets 无法正常解析 application.js,请使用 Ruby1.9。

簡介

这是一个基于 Rails Engine 开发的插件,為 Rails 專案增加縣,市區二級下拉列表。

安装

Gemfile

gem 'taiwan_city'

app/assets/javascripts/application.js

//= require 'jquery'
//= require 'taiwan_city/jquery.taiwan_city'

config/routes.rb

mount TaiwanCity::Engine => '/taiwan_city'

使用

在页面中加入选择框,示例代码使用 slim 格式

  .city-group
    select.city-select
      option --縣市--
      = options_for_select(TaiwanCity.list)
    select.city-select
      option --鄉鎮市區--

请留意:所有选择框都要有 city-select class,并都包含于 class='city-group' 的 DOM 元素之下。

選擇後的值前2碼為個人自行編碼,後3碼為台灣的郵遞區號,可使用 TaiwanCity.get('01100') 將代碼轉換為城市名稱。

        {"text": "臺北市" ,"id": "01000"},
        {"text": "新北市" ,"id": "02000"},
        {"text": "基隆"   ,"id": "03000"},
        {"text": "桃園"   ,"id": "04000"},
        {"text": "新竹"   ,"id": "05000"},
        {"text": "苗栗"   ,"id": "06000"},
        {"text": "台中"   ,"id": "07000"},
        {"text": "彰化"   ,"id": "08000"},
        {"text": "南投"   ,"id": "09000"},
        {"text": "雲林"   ,"id": "10000"},
        {"text": "嘉義"   ,"id": "11000"},
        {"text": "台南"   ,"id": "12000"},
        {"text": "高雄"   ,"id": "13000"},
        {"text": "屏東"   ,"id": "14000"},
        {"text": "宜蘭"   ,"id": "15000"},
        {"text": "花蓮"   ,"id": "16000"},
        {"text": "台東"   ,"id": "17000"},
        {"text": "澎湖"   ,"id": "18000"},
        {"text": "金門"   ,"id": "19000"},
        {"text": "馬祖"   ,"id": "20000"},
        {"text": "離島地區","id": "21000"}

貢獻

git clone https://github.com/motephyr/taiwan_city.git
cd taiwan_city
rake appraisal:install
cd spec/dummy
rails server # http://localhost:3000/taiwan_city

感謝作者