Skip to content

Instantly share code, notes, and snippets.

@jelera
Created December 4, 2019 14:59
Show Gist options
  • Save jelera/84f3927ad2c7055dcf6e3e2ff4e963a2 to your computer and use it in GitHub Desktop.
Save jelera/84f3927ad2c7055dcf6e3e2ff4e963a2 to your computer and use it in GitHub Desktop.
Sample seeds.rb file
#----------------------------------------------------------------------------#
#
# => Seed File
#
#----------------------------------------------------------------------------#
# Add this line, only for this project. Later on, you'll deal with Rails'
# gemfile
require 'faker'
number_of_users = 21
number_of_tweets = 300
#-------------------#
# Users
#-------------------#
number_of_users.times do
User.create(
first_name: Faker::Name.first_name,
last_name: Faker::Name.last_name,
country_origin: Faker::WorldCup.team,
age: (18..79).to_a.sample,
email: Faker::Internet.free_email,
address: Faker::Address.full_address,
password: Faker::Internet.password
)
end
#-------------------#
# Tweets
#-------------------#
number_of_tweets.times do
Tweet.create(
body: Faker::Hipster.paragraph(2, false, 4),
user_id: (1..number_of_users).to_a.sample
likes: (1..2000).to_a.sample,
)
end
#---------------------------------------------------#
# => Output
#---------------------------------------------------#
puts <<-OUTPUT
------------------------
DATA SUCCESSFULLY SEEDED
------------------------
#{User.all.count} users created
#{Tweet.all.count} tweets created
OUTPUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment