Example how to write seeds
Opened this issue · 1 comments
pycckuu commented
Hello,
could you please provide a minimal example of how to populate the database, assuming the table and the fields exist. Usual rails example doesn't work.
country_list = [
[ "Germany", 81831000 ],
[ "France", 65447374 ],
[ "Belgium", 10839905 ],
[ "Netherlands", 16680000 ]
]
country_list.each do |name, population|
Country.create!( name: name, population: population )
end
Thank you
miguelmota commented
I had to add the code inside a class extending ActiveRecord so for example your code would be:
class Country < ActiveRecord::Base
# ...
Country.create!( name: name, population: population )
end