I think I'm missing something really obvious here, but what is the second argument that everyone puts in for CSV.open method, in this case its 'wb', I've seen other letter(s) put here, but no one really explains what it does. What does it do?
CSV.open("path/to/file.csv", "wb") do |csv| csv << ["row", "of", "CSV", "data"] csv << ["another", "row"] # ... end
The ruby doc doesn't seem to give any explanation. http://www.ruby-doc.org/stdlib-2.0/libdoc/csv/rdoc/CSV.html
Thanks!
First, set up the application and seed in some data. Now, in post. rb , declare a method which will be responsible for generating data in CSV format. Depending upon your Rails version and the dependencies added, it's possible you'll need to add a require statement.
From the IO Open Mode documentation:
"r" Read-only, starts at beginning of file (default mode).
"r+" Read-write, starts at beginning of file.
"w" Write-only, truncates existing file to zero length or creates a new file for writing.
"w+" Read-write, truncates existing file to zero length or creates a new file for reading and writing.
"a" Write-only, starts at end of file if file exists, otherwise creates a new file for writing.
"a+" Read-write, starts at end of file if file exists, otherwise creates a new file for reading and writing.
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