Skip to content

Instantly share code, notes, and snippets.

@sedrickcz
Created March 21, 2018 20:06
Show Gist options
  • Save sedrickcz/bd43b2db8a88c926f975cf9c34c65586 to your computer and use it in GitHub Desktop.
Save sedrickcz/bd43b2db8a88c926f975cf9c34c65586 to your computer and use it in GitHub Desktop.
Add invoices to users
invoices = SmarterCSV.process('invoices.csv', { col_sep: ";" })
not_found = 0
ok = 0
invoices.each do |invoice|
user = Refinery::User.where(id: invoice[:user_id].to_i).first
if user
user.invoices.create number: invoice[:number].to_i, file_path: invoice[:invoice_file_name]
ok += 1
else
not_found += 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment