Created
December 24, 2014 07:53
-
-
Save pobing/5ab97690230cd564241c to your computer and use it in GitHub Desktop.
Ruby query db res and generate csv file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require 'csv' | |
desc 'Get all user email' | |
task :send_coupon do | |
date = Time.now.strftime("%Y%m%d%H%M%S") | |
path = "tmp/send_coupon_emails_#{date}.csv" | |
CSV.open(path, "wb") do |csv| | |
header = ["email","created_at","survey_count","passport_id"] | |
csv << header | |
User.where(:email.ne => nil).each do |u| | |
csv << [u.email, u.created_at.strftime("%Y-%m-%d"), u.surveys.count, u.passport_id] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment