I have a model class Person, and I create instances of them using:
person = Person.create!
Now I want to say that this person was born in California, USA, but in this peculiar way:
person = Person.create!({:name => "Matt", :born => "USCA"})
This means there are two characters to identify the country and another two characters to identify the state.
But I don’t want to store the string in the database, I want to store in a structured way, like:
| Name | Country | State |
| Matt | USA | California |
Where can I parse the string to assign the country and state based on it? Which method in the model?
Thanks in advance
Something like:
You may also find ActiveRecord::Aggregations::ClassMethods useful. With that you could consolidate your parsing and other logic to another class.