china_cities 1.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3e1eaae4597948822c7f38403883bb4510524cc4
|
|
4
|
+
data.tar.gz: 80c3add7533ae73bc3bc7c458c87eb5655811c2e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c65016bdde5ed5aa057adb8f4fbc2efbf082aac28e6ee75c088a81c1a452b8fbf15b0e5336b838e1068acaa53760440912701ecf5190283dea641dc7a186ba66
|
|
7
|
+
data.tar.gz: 81d2dc2f4ffa5c515d082281d4a464693693e98e366d5ea3da9cd25c5ec143dd74e8ccc11884329b0517b03ce2c216d2e0acfd4f006364983cc6ee561ed9afaa
|
data/README.md
CHANGED
|
@@ -1,60 +1,54 @@
|
|
|
1
|
+
|
|
2
|
+

|
|
3
|
+
|
|
1
4
|
## Installation
|
|
2
5
|
|
|
3
6
|
Add this line to your application's Gemfile:
|
|
4
7
|
|
|
5
|
-
gem 'china_cities'
|
|
8
|
+
gem 'china_cities', '~> 1.0'
|
|
6
9
|
|
|
7
10
|
|
|
8
11
|
And then execute:
|
|
9
12
|
|
|
10
13
|
bundle
|
|
11
14
|
|
|
12
|
-
```
|
|
13
|
-
|
|
14
15
|
## Usage
|
|
15
16
|
|
|
16
|
-
Run generator:
|
|
17
|
+
#### Run generator:
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
rails g china_cities install
|
|
20
|
+
rake db:migrate
|
|
20
21
|
|
|
21
|
-
rake db:migrate
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
#### Add these lines to app/assets/javascripts/application.js
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
//= require 'jquery.china_cities'
|
|
29
|
-
```
|
|
25
|
+
//= require 'jquery.china_cities'
|
|
26
|
+
$('.cities-select').china_city('by_name')
|
|
30
27
|
|
|
28
|
+
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.
|
|
31
29
|
|
|
32
|
-
Update config/routes.rb
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
mount ChinaCities::Engine => '/china_cities'
|
|
31
|
+
#### Update config/routes.rb
|
|
36
32
|
|
|
37
|
-
|
|
33
|
+
mount ChinaCities::Engine => '/china_cities'
|
|
38
34
|
|
|
39
35
|
|
|
40
|
-
In your view add:
|
|
36
|
+
#### In your view add:
|
|
41
37
|
|
|
42
38
|
```
|
|
43
|
-
|
|
44
|
-
.select.city-select
|
|
45
|
-
|
|
46
|
-
.select
|
|
47
|
-
.select.city-select
|
|
48
|
-
|
|
49
|
-
:coffee
|
|
50
|
-
$('.city-by-name').china_city('by_name')
|
|
39
|
+
.cities-select
|
|
40
|
+
= f.select :province, options_for_select(ChinaCity.provinces.map{|city|[city.name,city.name]}), { include_blank: 'please select' }, {class: 'city-select'}
|
|
41
|
+
= f.select :city, [], { include_blank: 'please select' }, {class: 'city-select'}
|
|
42
|
+
= f.select :district, [], { include_blank: 'please select' }, {class: 'city-select'}
|
|
51
43
|
|
|
52
44
|
```
|
|
53
45
|
|
|
54
|
-
|
|
46
|
+
#### Modile support (optional)
|
|
47
|
+
|
|
48
|
+
If you want to put a city list file to your app, you can download by the url: `/china_cities/json_file.json`
|
|
55
49
|
|
|
56
50
|
|
|
57
51
|
LICENSE.
|
|
58
52
|
-------------------------
|
|
59
53
|
|
|
60
|
-
This project rocks and uses MIT-LICENSE.
|
|
54
|
+
This project rocks and uses MIT-LICENSE.
|
data/lib/china_cities/version.rb
CHANGED
|
@@ -11,7 +11,7 @@ class ChinaCitiesGenerator < Rails::Generators::NamedBase
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def generate_migration
|
|
14
|
-
migration_template 'create_china_cities.rb', "db/migrate/
|
|
14
|
+
migration_template 'create_china_cities.rb', "db/migrate/create_china_cities.rb"
|
|
15
15
|
migration_template 'import_china_cities.rb', "db/migrate/import_china_cities.rb"
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -9,18 +9,15 @@ class ImportChinaCities < ActiveRecord::Migration
|
|
|
9
9
|
cities_nodes = province_node['cities']
|
|
10
10
|
options = province_node.delete_if {|k,v|k == 'cities'}
|
|
11
11
|
province = ChinaCity.create! options
|
|
12
|
-
puts province.name
|
|
13
12
|
if cities_nodes
|
|
14
13
|
cities_nodes.each do |city_node|
|
|
15
14
|
district_nodes = city_node['cities']
|
|
16
15
|
options = city_node.delete_if {|k,v|k == 'cities'}
|
|
17
16
|
city = ChinaCity.create! options.merge!({'parent_id' => province.id })
|
|
18
|
-
puts city.name
|
|
19
17
|
if district_nodes
|
|
20
18
|
district_nodes.each do |district_node|
|
|
21
19
|
options = district_node.delete_if {|k,v|k == 'cities'}
|
|
22
20
|
district = ChinaCity.create! options.merge!({'parent_id' => city.id})
|
|
23
|
-
puts district.name
|
|
24
21
|
end
|
|
25
22
|
end
|
|
26
23
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: china_cities
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- sharp
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-03-
|
|
11
|
+
date: 2016-03-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|