Reputation: 663
I would like to seed my seeds.rb file with a set of random strings.
I currently have a "name" category a "about_me" category such as:
Name: John, Jim, Joe, Jamie, Kim, Monica, Erica, Nicole
About_me: "I am blonde", "I am a brunette", "I have red hair", "I work at the museum"
I would like to seed 200 users with random sets of names & about_me's. How would i get around doing this? Can someone point me in the right direction?
I currently have:
200.times do |i|
User.create(rand(name: i, about_me: i))
That is not even close to working for me, so I was wondering how i can tackle this problem. Thank you in advance!
Upvotes: 1
Views: 1340
Reputation: 32758
How about something like not:
200.times do |i|
User.create(:name => SecureRandom.hex(12), :about_me => SecureRandom.hex(12))
If you don't care about the generated strings making sense at all. If you do need the strings to be "valid" then you will need to build a file or an array of names and pick random elements from it.
You can also look into the Faker gem which is used to generate fake data:
https://github.com/stympy/faker
Upvotes: 0
Reputation: 700
If you want the name
and about_me
to be completely random (i.e. make no sense at all), you can just generate random strings as shown in How to generate a random string in Ruby. However, if you want your information make some sense, you can create a list
of possible names and about me
strings and choose from random.
Upvotes: 1