I created City model and I have all cities that I need to store in city table in a .sql file. This sql file has all 'insert into' statements needed.
So, I would like to create a seed file to add all cities from the sql file. How could I seed a database using sql commands?
Thanks!
Using the following code you'll achieve what you want
connection = ActiveRecord::Base.connection();
connection.execute("SQL COMMANDS")
That would need to go in your seed.rb file
Then you'd need to execute rake db:seed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With