Skip to content

Instantly share code, notes, and snippets.

@AlexKVal
Forked from vamdt/city.rb
Last active March 9, 2019 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexKVal/3126103575b6df8f20533b5408fd0821 to your computer and use it in GitHub Desktop.
Save AlexKVal/3126103575b6df8f20533b5408fd0821 to your computer and use it in GitHub Desktop.
rails4 sti, custom "type" column name and value
class City < GeoEntity
def self.sti_name
3
end
end
class Country < GeoEntity
def self.sti_name
2
end
end
class GeoEntity < ActiveRecord::Base
self.inheritance_column = 'etype'
def self.find_sti_class(type_name)
type_name = self.name # so GeoEntity.new(etype: 2) returns Country
self
end
end
class State < GeoEntity
def self.sti_name
1
end
end
class Zip < GeoEntity
def self.sti_name
4
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment