GithubHelp home page GithubHelp logo

bastengao / chinese_regions_rails Goto Github PK

View Code? Open in Web Editor NEW
42.0 5.0 11.0 309 KB

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

Ruby 95.72% JavaScript 4.28%
rails chinese activerecord

chinese_regions_rails's Introduction

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

chinese_regions_rails's People

Contributors

bastengao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

chinese_regions_rails's Issues

能不能去除 sqlite 的依赖,换成 JSON 或者是别的什么的

[deploy@ls_s current]$ RAILS_ENV=production bundle exec rake db:seed:regions
rake aborted!
LoadError: incompatible library version - /srv/luxury-service/releases/419/vendor/bundle/ruby/2.3.0/gems/sqlite3-1.3.11/lib/sqlite3/sqlite3_native.so
/srv/luxury-service/releases/419/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.