geopolitical 2.0.0 → 3.2.0
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 +5 -5
- data/CHANGELOG.md +28 -0
- data/README.md +152 -73
- data/app/controllers/geopolitical/application_controller.rb +8 -0
- data/app/controllers/geopolitical/cities_controller.rb +44 -10
- data/app/controllers/geopolitical/geopolitical_controller.rb +11 -9
- data/app/controllers/geopolitical/hoods_controller.rb +47 -9
- data/app/controllers/geopolitical/nations_controller.rb +45 -7
- data/app/controllers/geopolitical/regions_controller.rb +47 -7
- data/app/helpers/geopolitical/application_helper.rb +2 -0
- data/app/models/city.rb +149 -48
- data/app/models/concerns/geopolitocracy.rb +121 -34
- data/app/models/hood.rb +44 -18
- data/app/models/nation.rb +96 -17
- data/app/models/region.rb +42 -14
- data/app/views/geopolitical/cities/_city.html.haml +2 -5
- data/app/views/geopolitical/cities/_form.html.haml +25 -28
- data/app/views/geopolitical/cities/edit.html.haml +1 -0
- data/app/views/geopolitical/cities/index.html.haml +17 -20
- data/app/views/geopolitical/cities/new.html.haml +1 -0
- data/app/views/geopolitical/cities/show.html.haml +7 -7
- data/app/views/geopolitical/geopolitical/index.html.haml +7 -9
- data/app/views/geopolitical/hoods/_city.html.haml +2 -5
- data/app/views/geopolitical/hoods/_form.html.haml +21 -22
- data/app/views/geopolitical/hoods/edit.html.haml +1 -0
- data/app/views/geopolitical/hoods/index.html.haml +13 -18
- data/app/views/geopolitical/hoods/new.html.haml +1 -0
- data/app/views/geopolitical/hoods/show.html.haml +5 -5
- data/app/views/geopolitical/nations/_form.html.haml +11 -8
- data/app/views/geopolitical/nations/_nation.html.haml +5 -0
- data/app/views/geopolitical/nations/edit.html.haml +1 -0
- data/app/views/geopolitical/nations/index.html.haml +16 -20
- data/app/views/geopolitical/nations/new.html.haml +1 -0
- data/app/views/geopolitical/nations/show.html.haml +7 -7
- data/app/views/geopolitical/regions/_form.html.haml +10 -8
- data/app/views/geopolitical/regions/_region.html.haml +2 -5
- data/app/views/geopolitical/regions/edit.html.haml +1 -0
- data/app/views/geopolitical/regions/index.html.haml +12 -15
- data/app/views/geopolitical/regions/new.html.haml +1 -0
- data/app/views/geopolitical/regions/show.html.haml +5 -5
- data/app/views/layouts/geopolitical.html.haml +13 -15
- data/config/locales/geopolitical.en.yml +76 -0
- data/config/locales/geopolitical.pt.yml +77 -0
- data/geopolitical.gemspec +14 -12
- data/lib/geopolitical/engine.rb +3 -0
- data/lib/geopolitical/version.rb +3 -2
- data/lib/geopolitical.rb +23 -3
- metadata +42 -118
- data/.coveralls.yml +0 -1
- data/.gitignore +0 -11
- data/.rspec +0 -1
- data/.travis.yml +0 -26
- data/Gemfile +0 -15
- data/Guardfile +0 -24
- data/Rakefile +0 -25
- data/app/serializers/city_serializer.rb +0 -8
- data/app/serializers/nation_serializer.rb +0 -4
- data/app/serializers/region_serializer.rb +0 -4
- data/bin/rails +0 -8
- data/lib/tasks/geopolitical_tasks.rake +0 -4
- data/spec/dummy/README.rdoc +0 -28
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/config/application.rb +0 -27
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -29
- data/spec/dummy/config/environments/production.rb +0 -80
- data/spec/dummy/config/environments/test.rb +0 -36
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -12
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/mongoid.yml +0 -63
- data/spec/dummy/config/routes.rb +0 -56
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/test.log +0 -23532
- data/spec/dummy/public/404.html +0 -58
- data/spec/dummy/public/422.html +0 -58
- data/spec/dummy/public/500.html +0 -57
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/fabricators/city_fabricator.rb +0 -6
- data/spec/fabricators/hood_fabricator.rb +0 -5
- data/spec/fabricators/nation_fabricator.rb +0 -4
- data/spec/fabricators/region_fabricator.rb +0 -5
- data/spec/models/city_spec.rb +0 -158
- data/spec/models/hood_spec.rb +0 -47
- data/spec/models/nation_spec.rb +0 -53
- data/spec/models/region_spec.rb +0 -20
- data/spec/spec_helper.rb +0 -57
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6eab76b546c1fe68a2b74c24193504f349c650ef97a5982cc87ee5fb74769d4e
|
|
4
|
+
data.tar.gz: 3301e6d264d6446a0663941819b76b64f956e83f89a16e5bcf70f87644abe616
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e4b582dacaf75fe5584450b61ee55d05bab5e15565ee7ee31c0104a852fcd1d28853fef45aa11c5de67bc48d9be8f18997789032fed639dd4deba8a5cd8e45ad
|
|
7
|
+
data.tar.gz: 1461b8bf452628a21c708f7c884d72301d0ac421079671b554e1aa2d4816064adafde8595c95c988936b52f85b5996c37bd27e08c00ee8e1d31461f88c200e68
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 3.2.0
|
|
4
|
+
|
|
5
|
+
- Slugs work in every script: `東京` → `東京`, `Санкт-Петербург` → `санкт-петербург`. Non-Latin names were previously invalid (blank slug). Accents are stripped via NFKD (`Hà Nội` → `ha-noi`). Underscores now become hyphens.
|
|
6
|
+
- `Geopolitocracy.slugify(text)` is public; `slug=`, `.search` and `Hood` all use it.
|
|
7
|
+
- `Nation['br']` — find by abbr, any case.
|
|
8
|
+
- City name uniqueness is now scoped by nation **and** region; region-less cities in different nations no longer collide.
|
|
9
|
+
- Removed `==`/`<=>` overrides on City, Region, Hood (Mongoid's `_id` equality already matches the unique indexes) and `Hood#as_json`.
|
|
10
|
+
- Removed empty rake task and RDoc task.
|
|
11
|
+
- Tested on Ruby 3.2 through 4.0 (CI matrix); `required_ruby_version` is now `>= 3.2` (Rails 8 / the test suite floor).
|
|
12
|
+
- Engine request specs cover full CRUD for all four resources.
|
|
13
|
+
- `Geopolitical.parent_controller` lets a host app point the engine's controllers at one of its own, so the admin UI inherits the host's authentication. Defaults to `ActionController::Base` (unauthenticated), and the README now says so.
|
|
14
|
+
- **i18n**: every label, button, table header and flash in the engine now goes through `I18n`; `config/locales/geopolitical.en.yml` and `geopolitical.pt.yml` ship with the gem. Model and attribute names use Mongoid's `mongoid.models` / `mongoid.attributes` scopes, so `f.label :souls` translates for free.
|
|
15
|
+
- The dashboard and layout used `model_name.human.pluralize` for nav headings, which is English-only ("Regiãos"); they now use `model_name.human(count: 2)`.
|
|
16
|
+
|
|
17
|
+
### Fixes from review
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
- **City slugs are unique planet-wide again.** A city with no region is now suffixed with its nation abbr (`singapore-sg`, `victoria-sc`), mirroring the region suffix (`santos-sp`). Previously two region-less cities in different nations both slugged to the same string.
|
|
21
|
+
- `City`s unique slug index was never created: `Geopolitocracy` declared a plain `index({slug: 1})` that shadowed it. The concern no longer declares one; `Region` (which needs a non-unique one for `.search`) declares its own.
|
|
22
|
+
- `slugify` normalizes to NFC first — decomposed input (macOS filenames, some form posts) slugged as `sa-o-paulo`.
|
|
23
|
+
- Moving a city to another region now refreshes the cached `rbbr` and rebuilds the slug; it used to keep the old abbr forever.
|
|
24
|
+
- Renaming or moving a `Hood` rebuilds its slug instead of stacking prefixes (`rio-rj-santos-sp-gonzaga`).
|
|
25
|
+
- `Nation#lang=` keeps the nations other languages instead of wiping `langs` to a single entry.
|
|
26
|
+
- `Nation[]` returns `nil` for an unknown abbr instead of raising `DocumentNotFound`.
|
|
27
|
+
|
|
28
|
+
**Upgrading:** stored slugs are not rewritten until a document is saved again, so existing data is untouched � but region-less cities will pick up a nation suffix the next time they are saved, and `City.create_indexes` will now fail on a database that already holds duplicate city slugs. `geonames_local` depends on `geopolitical > 0.8.4` (no upper bound) and will pick this up on its next bundle.
|
data/README.md
CHANGED
|
@@ -1,91 +1,170 @@
|
|
|
1
|
-
Geopolitical
|
|
2
|
-
============
|
|
1
|
+
# Geopolitical
|
|
3
2
|
|
|
4
3
|
[](http://badge.fury.io/rb/geopolitical)
|
|
5
|
-
[](https://github.com/fireho/geopolitical/actions/workflows/ci.yml)
|
|
5
|
+
[](MIT-LICENSE)
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
_.--""--._ Nation ─┐ "Brasil" BR .br BRL +55
|
|
9
|
+
.' __ o '. │
|
|
10
|
+
/ .' \ \ Region ─┤ "São Paulo" SP America/Sao_Paulo
|
|
11
|
+
| / o | ~ | │
|
|
12
|
+
| \_ o / ~ | City ─┤ "São Paulo" sao-paulo-sp (-46.63, -23.55)
|
|
13
|
+
\ `-' ~ / │
|
|
14
|
+
'. ~ ~ ~ .' Hood ─┘ "Vila Madalena" sao-paulo-sp-vila-madalena
|
|
15
|
+
`--....--'
|
|
16
|
+
place.hood.city.region.nation.planet # => :earth
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**The whole planet as four Mongoid models.** Nation → Region → City → Hood,
|
|
20
|
+
with slugs that never collide, names in every script, geo queries, and a
|
|
21
|
+
fallback chain for phone/postal codes. Bring your own data (Geonames, IBGE,
|
|
22
|
+
a CSV, a hunch) — or let [geonames_local](https://github.com/nofxx/geonames_local)
|
|
23
|
+
fill it for you.
|
|
24
|
+
|
|
25
|
+
## Why not the other gems?
|
|
26
|
+
|
|
27
|
+
| gem | Nation | Region | City | Hood | DB | Geo | i18n names | Admin UI |
|
|
28
|
+
|------------------------------------------------------------|:------:|:------:|:----:|:----:|----------|:---:|:----------:|:--------:|
|
|
29
|
+
| [countries](https://github.com/countries/countries) | ✓ | ✓ | – | – | in-memory| – | ✓ | – |
|
|
30
|
+
| [city-state](https://github.com/loureirorg/city-state) | ✓ | ✓ | ✓ | – | in-memory| – | – | – |
|
|
31
|
+
| [geonames-rails](https://github.com/tanguyantoine/geonames-rails) | ✓ | ✓ | ✓ | – | AR | ✓ | – | – |
|
|
32
|
+
| [geonames_dump](https://github.com/kmmndr/geonames_dump) | ✓ | ✓ | ✓ | – | AR | ✓ | – | – |
|
|
33
|
+
| **geopolitical** | ✓ | ✓ | ✓ | ✓ | Mongoid | ✓ | ✓ | ✓ |
|
|
34
|
+
|
|
35
|
+
Static lists are great until a user wants *their* city in the dropdown, a
|
|
36
|
+
neighborhood on the address, or a query like "cities within 50km".
|
|
37
|
+
That's when you want documents, not constants.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
gem 'geopolitical'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Rails: it's an engine, models autoload. Optionally mount the admin UI:
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
# config/routes.rb
|
|
49
|
+
mount Geopolitical::Engine => '/geopolitical'
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**The admin UI has no authentication of its own** — it is a mountable engine, so
|
|
53
|
+
guarding it is the host app's job. Either constrain the mount:
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
authenticate :user, ->(user) { user.admin? } do
|
|
57
|
+
mount Geopolitical::Engine => '/geopolitical'
|
|
58
|
+
end
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
or hand the engine a controller of yours that already authenticates:
|
|
62
|
+
|
|
63
|
+
```ruby
|
|
64
|
+
# config/initializers/geopolitical.rb
|
|
65
|
+
Geopolitical.parent_controller = 'Admin::BaseController'
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Plain Ruby: configure Mongoid, then `require 'geopolitical'`.
|
|
69
|
+
|
|
70
|
+
### Languages
|
|
71
|
+
|
|
72
|
+
The engine ships `en` and `pt` (`config/locales/geopolitical.*.yml`) and follows
|
|
73
|
+
`I18n.locale` — model names, attribute labels, buttons and flashes all move together:
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
I18n.locale = :pt
|
|
77
|
+
City.model_name.human(count: 2) # => "Cidades"
|
|
78
|
+
Hood.human_attribute_name(:souls) # => "População"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Override a string by defining the same key in your app, or add a locale by copying
|
|
82
|
+
one of those two files. Note the model *data* is localized separately — `name` and
|
|
83
|
+
`alt` are `localize: true` fields, so a city carries its own name per language.
|
|
84
|
+
|
|
85
|
+
## Cheat sheet
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
```ruby
|
|
89
|
+
br = Nation.create!(name: 'Brasil', abbr: 'br', tld: '.br', cash: 'BRL', langs: %w[pt], phone: '55')
|
|
90
|
+
sp = Region.create!(name: 'São Paulo', abbr: 'SP', nation: br, timezone: 'America/Sao_Paulo')
|
|
91
|
+
sampa = City.create!(name: 'São Paulo', region: sp, souls: 12_000_000, geom: [-46.63, -23.55])
|
|
92
|
+
vila = Hood.create!(name: 'Vila Madalena', city: sampa)
|
|
93
|
+
|
|
94
|
+
Nation['br'] # => #<Nation BR> abbr is the _id, any case
|
|
95
|
+
Nation.find('BR') # same thing
|
|
96
|
+
sampa.slug # => "sao-paulo-sp" region suffix, no collisions
|
|
97
|
+
vila.slug # => "sao-paulo-sp-vila-madalena"
|
|
98
|
+
sampa.nation # => BR derived from the region, you may omit it
|
|
99
|
+
sampa.to_s # => "São Paulo/SP"
|
|
100
|
+
sampa.with_nation('-') # => "São Paulo-SP-BR"
|
|
101
|
+
sampa.population # => 12000000 alias of `souls`
|
|
102
|
+
vila.phone # => "55" hood → city → region → nation
|
|
103
|
+
br.currency # => "BRL" alias of `cash`
|
|
104
|
+
|
|
105
|
+
City.search('sao pa') # slug prefix, accent/case-insensitive
|
|
106
|
+
City.search('sao-paulo-sp', exact: true)
|
|
107
|
+
City.nearby(sampa.geom) # 2dsphere $near, needs City.create_indexes
|
|
108
|
+
City.population.first # biggest city
|
|
109
|
+
Region.ordered # by name
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Slugs are the API. They're stable, unique, URL-safe and they survive scripts
|
|
113
|
+
you can't transliterate:
|
|
9
114
|
|
|
10
|
-
|
|
115
|
+
```
|
|
116
|
+
"São Paulo" => "sao-paulo"
|
|
117
|
+
"Baden-Württemberg"=> "baden-wurttemberg"
|
|
118
|
+
"Hà Nội" => "ha-noi"
|
|
119
|
+
"St. Louis" => "st-louis"
|
|
120
|
+
"東京" => "東京"
|
|
121
|
+
"Санкт-Петербург" => "санкт-петербург"
|
|
122
|
+
"دبي" => "دبي"
|
|
123
|
+
```
|
|
11
124
|
|
|
12
|
-
|
|
13
|
-
|
|
125
|
+
Two Springfields? `springfield-il` and `springfield-ma`. Tokyo with a region
|
|
126
|
+
that has no abbr? `tokyo-東京都`. It just works.
|
|
14
127
|
|
|
15
|
-
|
|
128
|
+
## The models
|
|
16
129
|
|
|
130
|
+
```
|
|
131
|
+
Nation _id = abbr (ISO 3166-1 α2) gid tld cash code3 langs capital
|
|
132
|
+
└── Region abbr (ISO 3166-2) code timezone capital unique per nation
|
|
133
|
+
└── City geom (Point) area rbbr slug unique globally
|
|
134
|
+
└── Hood rank slug unique globally
|
|
135
|
+
```
|
|
17
136
|
|
|
18
|
-
|
|
19
|
-
|
|
137
|
+
Every model shares (via the `Geopolitocracy` concern):
|
|
138
|
+
`name` & `alt` (localized), `abbr`, `nick`, `ascii`, `code`, `slug`,
|
|
139
|
+
`souls`/`population`, `postal`, `phone`, `.search`, `.ordered`, `to_s`, `==`, `<=>`.
|
|
20
140
|
|
|
21
|
-
|
|
141
|
+
Names get titleized only when you shout or mumble: `'new york'` and
|
|
142
|
+
`'NEW YORK'` become `"New York"`; `'McAllen'` stays `"McAllen"`.
|
|
22
143
|
|
|
23
|
-
|
|
144
|
+
## Feeding it
|
|
24
145
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* Languages
|
|
29
|
-
* Geometries
|
|
30
|
-
* Postal codes
|
|
31
|
-
* Phone codes
|
|
146
|
+
[geonames_local](https://github.com/nofxx/geonames_local) downloads
|
|
147
|
+
[Geonames](http://download.geonames.org/export/dump/) dumps and writes
|
|
148
|
+
straight into these models:
|
|
32
149
|
|
|
150
|
+
```
|
|
151
|
+
geonames BR -c geonames.yml # all of Brasil: regions, cities, hoods
|
|
152
|
+
```
|
|
33
153
|
|
|
34
|
-
|
|
35
|
-
------------
|
|
154
|
+
Or hand-roll from any source — every model is just a Mongoid document.
|
|
36
155
|
|
|
37
|
-
##
|
|
156
|
+
## Development
|
|
38
157
|
|
|
39
|
-
|
|
158
|
+
```
|
|
159
|
+
bundle install
|
|
160
|
+
bundle exec rspec # needs a local mongod
|
|
40
161
|
|
|
41
|
-
|
|
162
|
+
```
|
|
42
163
|
|
|
43
|
-
|
|
44
|
-
|
|
164
|
+
Specs take a world tour (`spec/models/world_spec.rb`): Japan, Russia, Greece,
|
|
165
|
+
Egypt, India, Korea, Germany, the US, Singapore… add your country if it's
|
|
166
|
+
missing, that's the best PR you can send.
|
|
45
167
|
|
|
46
|
-
##
|
|
168
|
+
## License
|
|
47
169
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
## Phone codes
|
|
52
|
-
|
|
53
|
-
With the help of phonie, it's now easy to two way
|
|
54
|
-
map entities and phone codes.
|
|
55
|
-
|
|
56
|
-
## Postal codes
|
|
57
|
-
|
|
58
|
-
Great for address validation and form pre-population.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
Outside Rails
|
|
62
|
-
-------------
|
|
63
|
-
|
|
64
|
-
require 'geopolitical/models'
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
Naming
|
|
68
|
-
------
|
|
69
|
-
|
|
70
|
-
* Nation -> Country
|
|
71
|
-
* Region -> State/Province
|
|
72
|
-
* City -> District/Microregion
|
|
73
|
-
* Hood -> Zone/Neighbourhood
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
Each must be inside the former.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
Populate
|
|
80
|
-
--------
|
|
81
|
-
|
|
82
|
-
Use Geonames_local to populate data easily!
|
|
83
|
-
"geonames_local"(https://github.com/fireho/geonames_local)
|
|
84
|
-
|
|
85
|
-
Links
|
|
86
|
-
-----
|
|
87
|
-
|
|
88
|
-
http://download.geonames.org/export/dump/
|
|
89
|
-
http://www.statoids.com/ubr.html
|
|
90
|
-
|
|
91
|
-
This project rocks and uses MIT-LICENSE.
|
|
170
|
+
MIT. Bug reports and PRs at [fireho/geopolitical](https://github.com/fireho/geopolitical).
|
|
@@ -1,23 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Geopolitical
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class CitiesController < ApplicationController
|
|
5
|
+
before_action :set_city, only: %i[show edit update destroy]
|
|
6
|
+
before_action :set_form_options, only: %i[new edit create update]
|
|
7
|
+
|
|
8
|
+
def index
|
|
9
|
+
@cities = City.ordered
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def show; end
|
|
13
|
+
|
|
14
|
+
def new
|
|
15
|
+
@city = City.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def edit; end
|
|
19
|
+
|
|
20
|
+
def create
|
|
21
|
+
@city = City.new(city_params)
|
|
22
|
+
if @city.save
|
|
23
|
+
redirect_to city_path(@city), notice: t('geopolitical.flash.created', model: City.model_name.human)
|
|
24
|
+
else
|
|
25
|
+
render :new, status: :unprocessable_entity
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def update
|
|
30
|
+
if @city.update(city_params)
|
|
31
|
+
redirect_to city_path(@city), notice: t('geopolitical.flash.updated', model: City.model_name.human)
|
|
32
|
+
else
|
|
33
|
+
render :edit, status: :unprocessable_entity
|
|
34
|
+
end
|
|
35
|
+
end
|
|
6
36
|
|
|
7
|
-
def
|
|
8
|
-
@
|
|
37
|
+
def destroy
|
|
38
|
+
@city.destroy
|
|
39
|
+
redirect_to cities_path, notice: t('geopolitical.flash.destroyed', model: City.model_name.human)
|
|
9
40
|
end
|
|
10
41
|
|
|
11
42
|
private
|
|
12
43
|
|
|
13
|
-
def
|
|
44
|
+
def set_city
|
|
45
|
+
@city = City.find(params[:id])
|
|
14
46
|
end
|
|
15
47
|
|
|
16
|
-
def
|
|
48
|
+
def set_form_options
|
|
49
|
+
@nations = Nation.ordered.map { |nation| [nation.to_s, nation.id] }
|
|
50
|
+
@regions = Region.ordered.map { |region| [region.to_s, region.id] }
|
|
17
51
|
end
|
|
18
52
|
|
|
19
|
-
def
|
|
20
|
-
|
|
53
|
+
def city_params
|
|
54
|
+
params.require(:city).permit(:name, :slug, :nation_id, :region_id, :souls, :postal, :phone)
|
|
21
55
|
end
|
|
22
56
|
end
|
|
23
57
|
end
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Geopolitical
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
layout 'geopolitical'
|
|
4
|
+
class GeopoliticalController < ApplicationController
|
|
5
|
+
def index; end
|
|
5
6
|
|
|
6
|
-
def
|
|
7
|
-
|
|
8
|
-
@cities = City.all
|
|
7
|
+
def show
|
|
8
|
+
render :index
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
def new
|
|
12
|
+
redirect_to root_path
|
|
13
|
+
end
|
|
12
14
|
|
|
13
|
-
def
|
|
14
|
-
|
|
15
|
+
def edit
|
|
16
|
+
redirect_to root_path
|
|
15
17
|
end
|
|
16
18
|
end
|
|
17
19
|
end
|
|
@@ -1,18 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Geopolitical
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
class HoodsController < ApplicationController
|
|
5
|
+
before_action :set_hood, only: %i[show edit update destroy]
|
|
6
|
+
before_action :set_city_options, only: %i[new edit create update]
|
|
7
|
+
|
|
8
|
+
def index
|
|
9
|
+
@hoods = Hood.ordered
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def show; end
|
|
7
13
|
|
|
8
|
-
def
|
|
9
|
-
@
|
|
14
|
+
def new
|
|
15
|
+
@hood = Hood.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def edit; end
|
|
19
|
+
|
|
20
|
+
def create
|
|
21
|
+
@hood = Hood.new(hood_params)
|
|
22
|
+
if @hood.save
|
|
23
|
+
redirect_to hood_path(@hood), notice: t('geopolitical.flash.created', model: Hood.model_name.human)
|
|
24
|
+
else
|
|
25
|
+
render :new, status: :unprocessable_entity
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def update
|
|
30
|
+
if @hood.update(hood_params)
|
|
31
|
+
redirect_to hood_path(@hood), notice: t('geopolitical.flash.updated', model: Hood.model_name.human)
|
|
32
|
+
else
|
|
33
|
+
render :edit, status: :unprocessable_entity
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def destroy
|
|
38
|
+
@hood.destroy
|
|
39
|
+
redirect_to hoods_path, notice: t('geopolitical.flash.destroyed', model: Hood.model_name.human)
|
|
10
40
|
end
|
|
11
41
|
|
|
12
42
|
private
|
|
13
43
|
|
|
14
|
-
def
|
|
15
|
-
@
|
|
44
|
+
def set_hood
|
|
45
|
+
@hood = Hood.find(params[:id])
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def set_city_options
|
|
49
|
+
@cities = City.ordered.map { |city| [city.to_s, city.id] }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def hood_params
|
|
53
|
+
params.require(:hood).permit(:name, :slug, :city_id, :souls, :rank, :postal, :phone)
|
|
16
54
|
end
|
|
17
55
|
end
|
|
18
56
|
end
|
|
@@ -1,13 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Geopolitical
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
class NationsController < ApplicationController
|
|
5
|
+
before_action :set_nation, only: %i[show edit update destroy]
|
|
6
|
+
|
|
7
|
+
def index
|
|
5
8
|
@nations = Nation.ordered
|
|
6
9
|
end
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
def show; end
|
|
12
|
+
|
|
13
|
+
def new
|
|
14
|
+
@nation = Nation.new
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def edit; end
|
|
18
|
+
|
|
19
|
+
def create
|
|
20
|
+
@nation = Nation.new(nation_params)
|
|
21
|
+
if @nation.save
|
|
22
|
+
redirect_to nation_path(@nation), notice: t('geopolitical.flash.created', model: Nation.model_name.human)
|
|
23
|
+
else
|
|
24
|
+
render :new, status: :unprocessable_entity
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def update
|
|
29
|
+
if @nation.update(nation_params)
|
|
30
|
+
redirect_to nation_path(@nation), notice: t('geopolitical.flash.updated', model: Nation.model_name.human)
|
|
31
|
+
else
|
|
32
|
+
render :edit, status: :unprocessable_entity
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def destroy
|
|
37
|
+
@nation.destroy
|
|
38
|
+
redirect_to nations_path, notice: t('geopolitical.flash.destroyed', model: Nation.model_name.human)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def set_nation
|
|
44
|
+
@nation = Nation.find(params[:id])
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def nation_params
|
|
48
|
+
params.require(:nation).permit(:name, :abbr, :slug, :lang, :cash, :code, :code3, :tld, :postal, :phone)
|
|
49
|
+
end
|
|
12
50
|
end
|
|
13
51
|
end
|
|
@@ -1,16 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Geopolitical
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
class RegionsController < ApplicationController
|
|
5
|
+
before_action :set_region, only: %i[show edit update destroy]
|
|
6
|
+
before_action :set_nation_options, only: %i[new edit create update]
|
|
7
|
+
|
|
8
|
+
def index
|
|
9
|
+
@regions = Region.ordered
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def show; end
|
|
5
13
|
|
|
6
|
-
def
|
|
7
|
-
@
|
|
14
|
+
def new
|
|
15
|
+
@region = Region.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def edit; end
|
|
19
|
+
|
|
20
|
+
def create
|
|
21
|
+
@region = Region.new(region_params)
|
|
22
|
+
if @region.save
|
|
23
|
+
redirect_to region_path(@region), notice: t('geopolitical.flash.created', model: Region.model_name.human)
|
|
24
|
+
else
|
|
25
|
+
render :new, status: :unprocessable_entity
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def update
|
|
30
|
+
if @region.update(region_params)
|
|
31
|
+
redirect_to region_path(@region), notice: t('geopolitical.flash.updated', model: Region.model_name.human)
|
|
32
|
+
else
|
|
33
|
+
render :edit, status: :unprocessable_entity
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def destroy
|
|
38
|
+
@region.destroy
|
|
39
|
+
redirect_to regions_path, notice: t('geopolitical.flash.destroyed', model: Region.model_name.human)
|
|
8
40
|
end
|
|
9
41
|
|
|
10
42
|
private
|
|
11
43
|
|
|
12
|
-
def
|
|
13
|
-
@
|
|
44
|
+
def set_region
|
|
45
|
+
@region = Region.find(params[:id])
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def set_nation_options
|
|
49
|
+
@nations = Nation.ordered.map { |nation| [nation.to_s, nation.id] }
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def region_params
|
|
53
|
+
params.require(:region).permit(:name, :abbr, :slug, :nation_id, :timezone, :postal, :phone)
|
|
14
54
|
end
|
|
15
55
|
end
|
|
16
56
|
end
|