lundi 23 juillet 2018

Issue writing data to csv file in ruby

I have an issue writing to a CSV file in ruby and can't figure out.

> header = "Full Name, Email, Phone Number" csv_file =
> CSV.open("myfile.csv", "wb") do |csv|
>     csv << header
>     inactive_users_id.each do |inactive_id|  #inactive_users_id is just an array on integers, which represent user id
>         full_name = User.find(inactive_id).full_name
>         email = User.find(inactive_id).email
>         phone_num = User.find(inactive_id).phone_number
>         desired_info = Array.new
>         desired_info.push(full_name)
>         desired_info.push(email)
>         desired_info.push(phone_num)
>         csv << desired_info
>       end 
>    end

I do get following errors:

  1. undefined method `map' for "Full Name, Email, Phone Number":String
  2. if I remove line csv << header my csv file is literally like this: [138] --> which represents the id and other things are not there.

What could be the issue? Thank you!

Aucun commentaire:

Enregistrer un commentaire