Coder Social home page Coder Social logo

guojhq / china_cities Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cjunyuan/china_cities

0.0 2.0 0.0 216 KB

**省市区三级联动, 支持数据库集成

License: MIT License

Ruby 99.55% CoffeeScript 0.08% HTML 0.25% JavaScript 0.07% CSS 0.06%

china_cities's Introduction

china_cities

Installation

Add this line to your application's Gemfile:

gem 'china_cities', '~> 1.0'

And then execute:

bundle

Usage

Run generator:

rails g china_cities install
rake db:migrate

Add these lines to app/assets/javascripts/application.js

//= require 'jquery.china_cities'
$('.cities-select').china_city('by_name')

Notice:by_name means it will generate the options with the city name value, and you can choose by_id and by_code as well.

Update config/routes.rb

mount ChinaCities::Engine => '/china_cities'

In your view add:

.cities-select
    = f.select :province, options_for_select(ChinaCity.provinces.map{|city|[city.name,city.name]}), { include_blank: 'please select' }, {class: 'city-select'}
    = f.select :city, [], { include_blank: 'please select' }, {class: 'city-select'}
    = f.select :district, [], { include_blank: 'please select' }, {class: 'city-select'}

Modile support (optional)

If you want to put a city list file to your app, you can download by the url: /china_cities/json_file.json

LICENSE.

This project rocks and uses MIT-LICENSE.

china_cities's People

Contributors

sharp avatar

Watchers

James Cloos avatar hua avatar

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.