class City
Public Class Methods
all()
click to toggle source
# File lib/city.rb, line 18 def self.all self.where( deleted_at: nil, is_active: true ).order_by( name: :desc ) end
clear()
click to toggle source
# File lib/city.rb, line 57 def self.clear if Rails.env.test? City.all.each { |r| r.remove } end end
for_homepage()
click to toggle source
# File lib/city.rb, line 84 def self.for_homepage cities = City.all.order_by( :name => :asc ) cities = cities.delete_if do |c| ( false == c.is_feature ) && ( 0 == c.galleries.length ) && ( 0 == c.reports.length ) end return cities end
list()
click to toggle source
# File lib/city.rb, line 46 def self.list out = self.order_by( :name => :asc ) # no_city = City.where( :cityname => 'no_city' ).first || City.create( :cityname => 'no_city', :name => 'No City' ) [['', nil]] + out.map { |item| [ item.name, item.id ] } end
list_citynames(lang = 'en')
click to toggle source
# File lib/city.rb, line 52 def self.list_citynames lang = 'en' out = self.order_by( :name => :asc ) [['', nil]] + out.map { |item| [ item['name_'+lang], item.cityname ] } end
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/city.rb, line 92 def self.method_missing name, *args, &block city = City.where( :cityname => name ).first return city if city super end
n_features()
click to toggle source
# File lib/city.rb, line 63 def self.n_features 4 end
Public Instance Methods
j_reports(args = {})
click to toggle source
# File lib/city.rb, line 71 def j_reports args = {} out = [] self.reports.each do |r| rr = r.clone rr[:username] = r.user.username rr.created_at = r.created_at # pretty_date( r.created_at ) rr[:tag_name] = r.tag.name unless r.tag.blank? rr[:tag_name] ||= '' out << rr end return out end
n_features()
click to toggle source
# File lib/city.rb, line 66 def n_features 4 end
slug()
click to toggle source
# File lib/city.rb, line 11 def slug; cityname; end
slug=(s;)
click to toggle source
# File lib/city.rb, line 12 def slug= s; cityname = s; end