Write a Simple CSV in rails
Mon May 11 2020 16:38:22 GMT+0000 (Coordinated Universal Time)
Saved by @ayazahmadtarar #ruby #rubyonrails
Write a simple CSV in rails
customMon May 11 2020 16:38:22 GMT+0000 (Coordinated Universal Time)
Saved by @ayazahmadtarar #ruby #rubyonrails
Write a simple CSV in rails
custom
Comments
Anonymous - Fri May 15 2020 19:38:50 GMT+0000 (Coordinated Universal Time)
file = "#{Rails.root}/public/users.csv" headers = ["Name", "Company Name", "Email", "Role", "Team Name"] CSV.open(file, 'w', write_headers: true, headers: headers) do |writer| Team.all.each do |team| team.users.each do |user| writer << [user.name, user.company_name , user.email, user.roles&.first&.name, team.name] end end end