Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example how to write seeds #158

Open
pycckuu opened this issue Sep 30, 2019 · 1 comment
Open

Example how to write seeds #158

pycckuu opened this issue Sep 30, 2019 · 1 comment

Comments

@pycckuu
Copy link

pycckuu commented Sep 30, 2019

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

@pycckuu pycckuu changed the title Example how to write a seeds Example how to write seeds Oct 1, 2019
@miguelmota
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants