Let's say I have User(name, password, email, zip code)
table and I want to generate User objects with random data.
Is there a command( to use on rails console), which does that? something like User.generate.
Let's say I have User(name, password, email, zip code)
table and I want to generate User objects with random data.
Is there a command( to use on rails console), which does that? something like User.generate.
After adding the Faker gem to your gemfile, add this to your user.rb file.
def self.generate_new
name = Faker::Name.name
password = "foobar"
email = Faker::Internet.email
zip = Faker::Address.zip
User.create!(name: name,
passowrd: password,
email: email,
zip: zip)
end
After restarting your console, the command User.generate_new
should run this command and generate a new user with random inputs.
Take a look at this gem: https://github.com/stympy/faker
It creates fake data for objects.