I built a Customer Support System a few days ago and started to think of a way to seed my rails database with random data for testing without having to manually type in the data. This may not be the best way to do it, but it works and allows you to test your application. We want a way to generate users that have tickets and also have comments without having to manually type in a value for each field. Let's start with the basic schema of the DB. Our Database, schema and migrations have already been generated and the main focus here will be on seeding the database. First, install the by adding it to your list of gems in your gemfile. faker gem gem 'faker' then run bundle install Once done, head into your file inside the directory In here, require the at the beginning. seeds.rb db . faker gem require 'faker' Next, let's create using fake data from the . Users faker gem The Faker attributes you can use are all available from the . faker GitHub page role: %w[customer admin agent].sample # a can have only one of these roles user The line above may look a little strange — we’ve designed our model to only accept one of the values in [“customer”, “admin”, “agent”] as the values assigned to for users. calling on the array causes the code to select one of the three possible values. role .sample I’ve added some comments using the symbol beside the lines. # Next, let’s create Remember that each ticket belongs to a As such, we’ll need to find a way to assign tickets to users randomly. Tickets. User. The line above is used to generate a random number between 1 and 20. Recall that our were assigned between 1 and 20. users Id’s Finally, let’s generate comments that belong to a and is tied to a . User ticket Once done, simply run rails db :seed You can check that everything went well by checking your . rails console