Is there a way to get the Faker gem to generate 'correlated' city and country code values?
For example,
I'm doing this:
FactoryGirl.define do
factory :location do
...
city {Faker::Address.city}
country_code {['US', 'CA'].sample}
...
end
end
But there is no guarantee that the city
will actual reside in country_code
.
I'd settle for something like:
postal_code {Faker::Address.postcode(['US', 'CA'].sample) }
Which I could then geocode to get the other values.
This gem is a port of Perl's Data::Faker library that generates fake data.
Installation of the faker gem is very straightforward. The Faker README is very detailed and provides a great deal of information. To install the faker gem simply type gem install faker in your terminal. After the gem installation is complete, open your rails app and go to your seeds file to begin using Faker.
You can customize based on locales: https://github.com/stympy/faker#customization
So you can create or modify a locale file, see this example: https://github.com/stympy/faker/blob/master/lib/locales/en-NEP.yml
Then you can set what the default country should be and also what states do you want to use
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With