In order to populate my Rails application with fake data I often do this:
person = Person.create(
:first_name => Faker::Name.first_name,
:last_name => Faker::Name.last_name,
:email => Faker::Internet.email
)
This might produce a person
like:
First name: Olivia
Last name: Kubera
Email: [email protected]
Is there a way to generate more coherent fake data like:
First name: Olivia
Last name: Kubera
Email: [email protected]
Or will I have to come up with something of my own to achieve this?
You can pass a name to Faker::Internet.email
to generate a fake email address for that person. You'll have to do a bit more work but not too much:
first_name = Faker::Name.first_name
last_name = Faker::Name.last_name
person = Person.create(
:first_name => first_name
:last_name => last_name
:email => Faker::Internet.email(first_name + "." + last_name)
)
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