<commit_before># TaiwanCityDistsHelper

Generate Taiwan City and Districts models with dynamic select boxes

輕鬆產生台灣鄉鎮市的 model relation 以及動態 select box

## Installation

Add this line to your application's Gemfile:

    gem 'taiwan_city_dists_helper'

And then execute:

    $ bundle install

## Preparation

    1. bundle exec rails g tcdh:table
    2. bundle exec rails db:migrate
    3. bundle exec rails tcdh:fetch
    4. add //= require taiwan_city_dists_helper to your application.js ( webpacker not supported )

Make sure your object ( let's say Customer ) has relations with city and dist, so you have to
add city\_id and dist\_id to your customers table, and define belongs_to in your customer.rb

    class Customer < ActiveRecord::Base
      belongs_to :city
      belongs_to :dist
    end

## Helper

### render\_city\_select(FormObject, CollectionOfCities, IncludeBlank?=false)
will render

    <select id="customer_city_id" name="customer[city_id]">
    <option value="1">臺北市</option>
    <option value="2">新北市</option>
    <option value="3">臺中市</option>
    .....
    </select>

### render\_dist\_select(FormObject, CollectionOfDists, IncludeBlank?=false)
will render

    <select id="customer_dist_id" name="customer[dist_id]"><commit_msg>modify README.md<commit_after># TaiwanCityDistsHelper

Generate Taiwan City and Districts models with dynamic select boxes

輕鬆產生台灣鄉鎮市的 model relation 以及動態 select box ( webpacker 暫不支援 )

## Installation

Add this line to your application's Gemfile:

    gem 'taiwan_city_dists_helper'

And then execute:

    $ bundle install

## Preparation

    1. bundle exec rails g tcdh:table
    2. bundle exec rails db:migrate
    3. bundle exec rails tcdh:fetch
    4. add //= require taiwan_city_dists_helper to your application.js ( webpacker not supported )

Make sure your object ( let's say Customer ) has relations with city and dist, so you have to
add city\_id and dist\_id to your customers table, and define belongs_to in your customer.rb

    class Customer < ActiveRecord::Base
      belongs_to :city
      belongs_to :dist
    end

## Helper ( webpacker not supported )

### render\_city\_select(FormObject, CollectionOfCities, IncludeBlank?=false)
will render

    <select id="customer_city_id" name="customer[city_id]">
    <option value="1">臺北市</option>
    <option value="2">新北市</option>
    <option value="3">臺中市</option>
    .....
    </select>

### render\_dist\_select(FormObject, CollectionOfDists, IncludeBlank?=false)
will render

    <select id="customer_dist_id" name="customer[dist_id]">
{'fraction_non_alphanumeric': 0.0926505082095387, 'fraction_numerical': 0.00547302580140735, 'mean_word_length': 4.0773809523809526, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3643080', 'n_tokens_mistral': 852, 'n_tokens_neox': 828, 'n_words': 251}