Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.63 KB | None | 0 0
  1. funz_id_with_title = []
  2. error_funz = []
  3.  
  4. CSV.new(open('/Users/dan/Downloads/Funzing_Talks_-_title_changes.csv'), :headers => :first_row).each do |row|
  5.    funz_id_with_title << row.to_hash
  6.  end
  7.  
  8.  funz_ids = funz_id_with_title.map { |row| row['Id'] }
  9.  all_funz = Funz.where(id: funz_ids)
  10.  
  11.  
  12. all_funz.find_each do |funz|
  13.   begin
  14.     puts "working on funz #{funz.id}"
  15.     funz_find = (funz_id_with_title.find { |x| x['Id'] == f.id.to_s})
  16.     funz_find["Title"].length > 53 ? error_funz << funz.id : funz.update_column(:title, funz_find["Title"])
  17.   rescue => e
  18.     error_funz << funz.id
  19.     puts "ERROR: #{e} - #{funz.id}"
  20.   end
  21. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement