Guest User

Untitled

a guest
Nov 20th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. require 'csv'
  2.  
  3. file = "#{Rails.root}/public/company_data.csv"
  4.  
  5. companies = Company.order(:code)
  6.  
  7. column_headers = ["code", "name", "area"]
  8.  
  9. CSV.open(file, 'w', write_headers: true, headers: column_headers) do |csv|
  10. companies.each do |company|
  11. csv << [company.code, company.name, company.area ]
  12. end
  13. end
Add Comment
Please, Sign In to add comment