Is there a way to write a csv file using a hash instead of an array?
Something like this:
header_keys = :first_name, :last_name, :email
FasterCSV.open(“path/to/file.csv”, “w”) do |csv|
User.all.do |user|
csv << user
end
end
Thanks…
Is there a way to write a csv file using a hash instead of an array?
Something like this:
header_keys = :first_name, :last_name, :email
FasterCSV.open(“path/to/file.csv”, “w”) do |csv|
User.all.do |user|
csv << user
end
end
Thanks…
On Dec 20, 2010, at 4:30 PM, TomRossi7 wrote:
Is there a way to write a csv file using a hash instead of an array?
Something like this:header_keys = :first_name, :last_name, :email
FasterCSV.open(“path/to/file.csv”, “w”) do |csv|
User.all.do |user|
csv << user
csv << user.attributes.values_at(*header_keys)
To unsubscribe from this group, send email to
[email protected]
.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
.
Rob B.
[email protected] http://AgileConsultingLLC.com/
[email protected] http://GaslightSoftware.com/
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs