In the initializer, I have a huge hash COUNTRY_CODES , with the format:
{ :us => "United States, :de => "Germany" }
In my model, I want to confirm that the entered value:
- is present
- key of my country code hash
How to do it?
I can not use:
validates :country, :presence => true, :inclusion => { :in => COUNTRY_CODES }
I tried custom validators, but I get method errors when the value is nil. when I try to use value.to_sym, forcing me to check the validator and it becomes messy.
Trying to figure out the harshest and most effective way to do this.
Fred fickleberry iii
source share