Commit 395255b663255368d830732022eb8077f1b2a762
1 parent
c18509e8
Exists in
master
Adding article relation with states and cities
Showing
3 changed files
with
13 additions
and
2 deletions
Show diff stats
... | ... | @@ -0,0 +1,8 @@ |
1 | +require_dependency 'article' | |
2 | + | |
3 | +class Article | |
4 | + | |
5 | + has_many :states, :through => :article_categorizations, :source => :category, :class_name => State | |
6 | + has_many :cities, :through => :article_categorizations, :source => :category, :class_name => City | |
7 | + | |
8 | +end | ... | ... |
lib/ext/user.rb
lib/juventude_plugin/api.rb
... | ... | @@ -3,13 +3,13 @@ class JuventudePlugin::API < Grape::API |
3 | 3 | resource :states do |
4 | 4 | |
5 | 5 | get do |
6 | - states = State.select([:id, :name]) | |
6 | + states = State.select([:id, :name]).order(:name) | |
7 | 7 | present states |
8 | 8 | end |
9 | 9 | |
10 | 10 | get ':id/cities' do |
11 | 11 | state = State.find(params[:id]) |
12 | - cities = City.where(:parent_id => state.id).select([:id, :name]) | |
12 | + cities = City.where(:parent_id => state.id).select([:id, :name]).order(:name) | |
13 | 13 | present cities |
14 | 14 | end |
15 | 15 | ... | ... |