Guest User

Untitled

a guest
Apr 25th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. require "faster_csv"
  2.  
  3. your_csv_file = "#{RAILS_ROOT}/db/yourfile.csv"
  4.  
  5. FCSV.foreach( "#{library_file}", :headers => true, :header_converters => :symbol, :col_sep => "\t") do |line|
  6. # now you have access to an array called line
  7. first_value = line[0]
  8. second_value = line[1]
  9. # etc. etc.
  10.  
  11. # if you do this next line, now you can access the rows like: atts[:name_of_column]
  12. atts = line.to_hash
  13.  
  14. # here you can create active record models, using things like:
  15. Model.find_or_create_by_name_and_body(atts[:name], atts[:body])
  16.  
  17. end
Add Comment
Please, Sign In to add comment