Commit 82f8f051425a046bb144f831dcb1a947334d972d
1 parent
db16ebfe
Exists in
master
and in
2 other branches
refactoring load state and city
Showing
2 changed files
with
10 additions
and
13 deletions
Show diff stats
lib/ext/person.rb
| ... | ... | @@ -6,17 +6,4 @@ class Person |
| 6 | 6 | |
| 7 | 7 | attr_accessible :orientacao_sexual, :identidade_genero, :transgenero, :tipo, :etnia |
| 8 | 8 | |
| 9 | - def city= city | |
| 10 | - city = City.find(city) unless city.kind_of?(City) | |
| 11 | - self.region = city | |
| 12 | - end | |
| 13 | - | |
| 14 | - def city | |
| 15 | - self.region | |
| 16 | - end | |
| 17 | - | |
| 18 | - def state | |
| 19 | - self.region.parent if self.region | |
| 20 | - end | |
| 21 | - | |
| 22 | 9 | end | ... | ... |
lib/juventude_plugin/api.rb
| ... | ... | @@ -7,11 +7,21 @@ class JuventudePlugin::API < Grape::API |
| 7 | 7 | present states |
| 8 | 8 | end |
| 9 | 9 | |
| 10 | + get ':id' do | |
| 11 | + state = State.select([:id, :name]).find(params[:id]) | |
| 12 | + present state | |
| 13 | + end | |
| 14 | + | |
| 10 | 15 | get ':id/cities' do |
| 11 | 16 | state = State.find(params[:id]) |
| 12 | 17 | cities = City.where(:parent_id => state.id).select([:id, :name]).order(:name) |
| 13 | 18 | present cities |
| 14 | 19 | end |
| 15 | 20 | |
| 21 | + get ':id/cities/:city_id' do | |
| 22 | + city = City.select([:id, :name]).find(params[:city_id]) | |
| 23 | + present city | |
| 24 | + end | |
| 25 | + | |
| 16 | 26 | end |
| 17 | 27 | end | ... | ... |