Import Data From A CSV File In Rails Or Ruby

Posted By Weston Ganger

I needed to do some importing. CSV is the easiest format to work with for import data.
Also if you didn't know you can sometimes save your xls as a CSV for faster/easier access without additional gems.

Its built right into ruby you just need to require it.

CSV.foreach(filename, headers: true) do |row|
  Place.create(row.to_hash)
end

Related External Links:

Article Topic:Software Development - Ruby / Rails

Date:February 11, 2016