Class: WorldDbAdmin::CountriesController

Inherits:
WorldDbAdminController show all
Defined in:
app/controllers/world_db_admin/countries_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject

GET /countries



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/controllers/world_db_admin/countries_controller.rb', line 65

def index

  ## for now store order and tag in session
  ## todo/fix: find a  better way to store user order and filter settings
  
  session[:order] = order = params[:order] || session[:order] || 'title'
  session[:tag]   = tag   = params[:tag]   || session[:tag]   || 'all'
  
  @countries = nil    

  if order == 'pop'
    @countries = Country.by_pop
  elsif order == 'area'
    @countries = Country.by_area
  elsif order == 'title'    
    @countries = Country.by_title
  else
    @countries = Country.by_title
  end
 
=begin        
  if tag == 'all'
    ## do nothing; include all
  else 
    ## fix/todo:  add with_tag() scope to Country!!!    
    country_ids = Tag.find_by_key!( tag ).country_ids
  
    @countries = @countries.find( country_ids )      
  end
=end
  @countries = @countries.where( c: true ).all
end

#index_territoriesObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/controllers/world_db_admin/countries_controller.rb', line 98

def index_territories

  session[:order] = order = params[:order] || session[:order] || 'title'
  session[:tag]   = tag   = params[:tag]   || session[:tag]   || 'all'
  
  @countries = nil    

  if order == 'pop'
    @countries = Country.by_pop
  elsif order == 'area'
    @countries = Country.by_area
  elsif order == 'title'    
    @countries = Country.by_title
  else
    @countries = Country.by_title
  end

=begin        
  if tag == 'all'
    ## do nothing; include all
  else 
    ## fix/todo:  add with_tag() scope to Country!!!    
    country_ids = Tag.find_by_key!( tag ).country_ids
  
    @countries = @countries.find( country_ids )      
=end
  @countries = @countries.where( d: true ).all
end

#shortcutObject

GET /:key e.g /at or /us etc.



129
130
131
132
# File 'app/controllers/world_db_admin/countries_controller.rb', line 129

def shortcut
  @country = Country.find_by_key!( params[:key] )
  render :show
end

#showObject

GET /countries/:id e.g. /countries/1



135
136
137
# File 'app/controllers/world_db_admin/countries_controller.rb', line 135

def show
  @country = Country.find( params[:id] )
end