Before starting, We assumes that you have a table `authors` and its `model`, if not, you can do
railsgscaffoldauthorname
Seeding tables can be done by many ways:
Open `db/seeds.rb` and paste
5.timesdo|i|Author.create(name: "John#{i}"end
First, Using `rake db:setup` if the database not set, where `rake db:setup` creates the database and make migrations and seed data from `db/seeds.rb`.
Then, You can check the `authors` table using `console`.
Second, Using
rakedb:seed
Which insert `seeds` from `db/seeds.rb`.
Last, Using migration as
railsgmigrationAddSeeds
This will create an empty migration file.
Then paste this seeding code:
5.timesdo|i|Author.create(name: "John#{i}"end
Then,
rakedb:migrate
Also, You can check the `authors` data using `rails c` or `browser`
Note, You can delete these seeds using