Skip to content

Instantly share code, notes, and snippets.

@vparihar01
Created April 10, 2013 11:22
Show Gist options
  • Save vparihar01/5353812 to your computer and use it in GitHub Desktop.
Save vparihar01/5353812 to your computer and use it in GitHub Desktop.
the snippet which creates a csv for the given object, we could aslo use streaming to do this same to save memory consumption.
csv_string = FasterCSV.generate do |csv|
csv << ["Idea Name","Total Votes count","Date Created","Created By"]
csv << [@idea.title, @idea.votes.size,@idea.created_at.strftime("%B %d, %Y"),@idea.created_by]
csv << ["Months","Total Votes count"]
votes_count.each_with_index do |i,j|
csv << [month_names[j] , votes_count[j] ]
end
end
send_data csv_string,
:type => "text/csv; charset=iso-8859-1; header=present",
:disposition => "attachment; filename=Idea.csv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment