The following ruby code is replacing the entire contents of the file. How can I just append to the end of the file and keep it's existing contents intact?
File.open("db/seeds.rb", "w") do |f|
f.write "Blog::Engine.load_seed"
end
Use append mode ("a"
):
File.open("db/seeds.rb", "a") do |f|
Here is a link to the docs, on the different modes you can specify when opening a file.
Write in append mode 'a'
File.write('db/seeds.rb', "Blog::Engine.load_seed", nil , mode: 'a')
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