Skip to content

Instantly share code, notes, and snippets.

@jonpaul
Created December 7, 2011 16:43
Show Gist options
  • Save jonpaul/1443528 to your computer and use it in GitHub Desktop.
Save jonpaul/1443528 to your computer and use it in GitHub Desktop.
def download
@email = User.emails.concat(Organization.emails).compact!
outfile = "members_" + Time.now.strftime("%D") + ".csv"
unless @email.blank?
data = CSV.generate do |csv|
csv << ['Email']
@email.each do |e|
csv << [e]
end
end
end
send_data data, :type => 'text/csv; charset=iso-8859-1; header=present', :disposition => "attachment; filename=#{outfile}"
flash.now[:notice] = "Export Complete!"
end
@jonpaul
Copy link
Author

jonpaul commented Dec 7, 2011

Send a CSV without writing a file, gogogadget send_data!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment