All Projects → bastengao → Chinese_regions_rails

bastengao / Chinese_regions_rails

中国省市区县数据库,包含行政编码,邮政编码,地区拼音和简拼

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Chinese regions rails

Stateful enum
A very simple state machine plugin built on top of ActiveRecord::Enum
Stars: ✭ 546 (+1336.84%)
Mutual labels:  activerecord, rails
Rein
Database constraints made easy for ActiveRecord.
Stars: ✭ 657 (+1628.95%)
Mutual labels:  activerecord, rails
Github Ds
A collection of Ruby libraries for working with SQL on top of ActiveRecord's connection
Stars: ✭ 597 (+1471.05%)
Mutual labels:  activerecord, rails
Order query
Find next / previous Active Record(s) in one query
Stars: ✭ 472 (+1142.11%)
Mutual labels:  activerecord, rails
Datagrid
Gem to create tables grids with sortable columns and filters
Stars: ✭ 921 (+2323.68%)
Mutual labels:  activerecord, rails
Zero downtime migrations
Zero downtime migrations with ActiveRecord 3+ and PostgreSQL
Stars: ✭ 513 (+1250%)
Mutual labels:  activerecord, rails
Mobility
Pluggable Ruby translation framework
Stars: ✭ 644 (+1594.74%)
Mutual labels:  activerecord, rails
Rails Pg Extras
Rails PostgreSQL database performance insights. Locks, index usage, buffer cache hit ratios, vacuum stats and more.
Stars: ✭ 432 (+1036.84%)
Mutual labels:  activerecord, rails
Activerecordextended
Adds additional postgres functionality to an ActiveRecord / Rails application
Stars: ✭ 830 (+2084.21%)
Mutual labels:  activerecord, rails
Activerecord Postgis Adapter
ActiveRecord connection adapter for PostGIS, based on postgresql and rgeo
Stars: ✭ 746 (+1863.16%)
Mutual labels:  activerecord, rails
Attribute normalizer
Adds the ability to normalize attributes cleanly with code blocks and predefined normalizers
Stars: ✭ 473 (+1144.74%)
Mutual labels:  activerecord, rails
Hold please
📞 Disable ActiveRecord callbacks in Rails for great justice!
Stars: ✭ 20 (-47.37%)
Mutual labels:  activerecord, rails
Activerecord Jdbc Adapter
JRuby's ActiveRecord adapter using JDBC.
Stars: ✭ 457 (+1102.63%)
Mutual labels:  activerecord, rails
Activerecord Multi Tenant
Rails/ActiveRecord support for distributed multi-tenant databases like Postgres+Citus
Stars: ✭ 526 (+1284.21%)
Mutual labels:  activerecord, rails
Strip attributes
🔪 An ActiveModel extension that automatically strips all attributes of leading and trailing whitespace before validation. If the attribute is blank, it strips the value to nil.
Stars: ✭ 441 (+1060.53%)
Mutual labels:  activerecord, rails
Unread
Handle unread records and mark them as read with Ruby on Rails
Stars: ✭ 638 (+1578.95%)
Mutual labels:  activerecord, rails
Deep pluck
Allow you to pluck attributes from nested associations without loading a bunch of records.
Stars: ✭ 385 (+913.16%)
Mutual labels:  activerecord, rails
Store model
Work with JSON-backed attributes as ActiveRecord-ish models
Stars: ✭ 410 (+978.95%)
Mutual labels:  activerecord, rails
Paper trail
Track changes to your rails models
Stars: ✭ 6,185 (+16176.32%)
Mutual labels:  activerecord, rails
Active record doctor
Identify database issues before they hit production.
Stars: ✭ 865 (+2176.32%)
Mutual labels:  activerecord, rails

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 到用户项目

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].