Skip to content

Instantly share code, notes, and snippets.

@lksv
Last active February 8, 2016 08:39
Show Gist options
  • Save lksv/0475964f4a7119f3b331 to your computer and use it in GitHub Desktop.
Save lksv/0475964f4a7119f3b331 to your computer and use it in GitHub Desktop.
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