Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

china_regions

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

china_regions

  • 1.0.8
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

ChinaRegions

Gem Version Build Status Coverage Status

ChinaRegions provides Ruby on Rails code for provinces, cities, and districts [prefecture-level cities] in China. The code need to requires Ruby (> 1.9.x) and Rails (> 4.0).

Data Sources

How to update data

If you are using ChinaRegions version 0.1.x be sure to run:

rails g china_regions:regions

to have the javascript file copied over into your project.

Installation

Add it to your Gemfile:

gem 'china_regions'

Run the following command to install it:

bundle install

Run the generator:

rails g china_regions:install

Then you can see the changes that happened to the console:

  • Copy db/migrate/xxxxxxxxxxx_create_china_regions_tables.rb to db/migrate folder.
  • Copy regions.en.yml and regions.zh.yml files to config/locales folders

Create tables (provinces, cities, districts):

rake db:migrate

Copy Models [Province, City, District] into your project:

rails g china_regions:regions

Newly added models:

  • create app/models/province.rb
  • create app/models/city.rb
  • create app/models/district.rb

Download and import the latest regions to your project:

rake china_regions:all

OR

rake china_regions:download
rake china_regions:import
  • Downloading regions from Administrative-divisions-of-China to db/regions folder.
    • db/regions/pca-code.json
  • Import the regions into provinces and cities, districts

Usage

Example:

= form_for @article do |f|

  = f.region_select [:province, :city, :district]

  # form_tag
  = region_select :article, :province_id
  = region_select :article, :city_id
  = region_select :article, :district_id

  OR

  = region_select :article, :province
  = region_select :article, :city
  = region_select :article, :district

  = f.submit class: 'btn'

Add prefix name:

= form_for @article do |f|

  = f.region_select [:province, :city, :district], :prefix => "home"
  = f.region_select [:province, :city, :district], :prefix => "work"

Pre-selected province:

= form_for @article do |f|
  = f.region_select [:province, :city, :district], province: "chongqing"

  OR

  = f.region_select [:province, :city, :district], province: "重庆市"

Prior choice:

= form_for @article do |f|
  = f.region_select [:province, :city, :district],
          priority: {
            province: ["重庆市"],
            district: %w(巴南区 北碚区 渝北区)
          }

Other languages

Contributing

We have a list of valued contributors. Check them all at: https://github.com/encoreshao/china_regions/graphs/contributors

License

Copyright © 2020-02 Encore Shao. See LICENSE for details.

FAQs

Package last updated on 02 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc