Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "faster_csv"
- your_csv_file = "#{RAILS_ROOT}/db/yourfile.csv"
- FCSV.foreach( "#{library_file}", :headers => true, :header_converters => :symbol, :col_sep => "\t") do |line|
- # now you have access to an array called line
- first_value = line[0]
- second_value = line[1]
- # etc. etc.
- # if you do this next line, now you can access the rows like: atts[:name_of_column]
- atts = line.to_hash
- # here you can create active record models, using things like:
- Model.find_or_create_by_name_and_body(atts[:name], atts[:body])
- end
Add Comment
Please, Sign In to add comment