Last active
February 8, 2016 08:39
-
-
Save lksv/0475964f4a7119f3b331 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LocalAdministrationUnit < ActiveRecord::Base | |
# it should be :vusc, :okres :obec :cast_obce :momc | |
belongs_to :ruian_locable, polymorphic: true | |
validates :ruian_locable_id, uniqueness: { scope: [:ruian_locable_type] } | |
validates :ruian_locable_id, presence: true | |
def title | |
return nil if ruian_locable.nil? | |
prefix = case ruian_locable | |
when Vusc then 'Vyšší územně samosprávný celek' | |
when Okres then 'Okres' | |
when Obec then 'Obec' | |
when CastObce then 'Část obce' | |
when Momc then 'Městský obvod / městská část' | |
else | |
fail "Unknown ruian_locable type: #{ruian_locable.class.to_s.inspect}" | |
end | |
[prefix, ruian_locable.try(:nazev)].join(' ') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment