EKOSM EKOSM - 1 year ago 109
Ruby Question

Save hash in the csv ruby

I have hash:

users = {
'name' => name,
'last_name' => last_name,
'photo' => photo,
'address' => address,

Save in csv:

CSV.open("users.csv", "a") {|csv| users.to_a.each {|elem| csv << elem}}


name, Jake
photo, http://avs.ru/leto_3434.jpg
address, NEW YORK
name, Dan
photo, http://avs.ru/leto_3423.jpg
address, NEW YORK

I need to get the file:

Jake,Kallen,http://avs.ru/leto_3434.jpg,NEW YORK

How to change my code to get what I need?
Help me please.

UPD: I forgot to point out that a lot of users

Answer Source
CSV.open("users.csv", "a") {|csv|
  csv << users.values

I think, you need this. If users hash will contains other data - csv will take it to

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download