Commit 395255b663255368d830732022eb8077f1b2a762

Authored by Caio Almeida
1 parent c18509e8
Exists in master

Adding article relation with states and cities

lib/ext/article.rb 0 → 100644
... ... @@ -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
... ... @@ -34,4 +34,7 @@ class User
34 34 self.person_data[:tipo] = value
35 35 end
36 36  
  37 + def category_ids= categories
  38 + self.person_data[:category_ids] = categories
  39 + end
37 40 end
... ...
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  
... ...