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

chinese_regions_rails

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chinese_regions_rails

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

chinese_regions_rails

中国省市区县数据库,包含 行政编码,邮政编码,地区拼音和简拼。 数据来源 https://github.com/xixilive/chinese_regions_db 。 支持 active_record 和 mongoid 。

安装

Gemfile

gem 'chinese_regions_rails'

Copy migrations

rails g chinese_regions:install

db migration and seed

rake db:migrate
rake db:seed:regions

使用

直接使用 Region model

class User < ActiveRecord::Base
  belongs_to :city, class_name: "ChineseRegions::Region"
end
使用 city-picker 作为表单输入

application.css 添加下面代码

*= require city-picker

application.js 中在 jQuery 后面引入文件

//= require city-picker.data
//= require city-picker
//= require chinese-regions

表单里可以使用 city_picker_tag(method, value, options)city_picker(method, options), 这两个标签只是简单的封装,options 可以传入任何东西, 比如 city-picer 的 level 和 simple 选项可以通过 data 传入 data: { level: :city, simple: true }

<%= form_tag do %>
  <div style="position: relative;">
    # Region model
    <%= city_picker_tag :city_id, @user.city %>
    # Regoin id
    <%= city_picker_tag :city_id, "610101", data: { level: :city } %>
  </div>
<% end %>

<% form_for @user do |f| %>
  <div style="position: relative;">
    <%= f.city_pciker :city_id %>
  </div>
<% end %>

Region model

class ChineseRegions::Region < ActiveRecord
  belogns_to :parent # 上级 region
  has_many :children # 下级 region
end

model 包含的属性

  • id
  • parent_id
  • level
  • name
  • alias
  • pinyin
  • abbr
  • zip

Change log

  • v1.0.0

    Break Change

    • 直接使用 engine 里的 ChineseRegions::Region model,而不是添加 model 到用户项目
    • 引入 city-picker
  • v0.1.*

    修改 Sqlite3 数据源到 json

  • v0.0.*

    生成 Region model 到用户项目

FAQs

Package last updated on 26 Apr 2017

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