Created
September 4, 2012 09:24
-
-
Save cantonic/3619074 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require "csv" | |
namespace :contact do | |
desc "Create CSV for all unsold Contacts" | |
task :create_csv => :environment do | |
@contact_count = [] | |
cities = City.where(:is_active => true).each do |city| | |
CSV.open("tmp/csv/#{city.name}-#{Date.today}.csv", "w", {:force_quotes=>true}) do |csv| | |
csv << ["Anrede", "Name", "Email", "Telefon", "Geburtsdatum", "Anmeldedatum", "Ort"] | |
contacts = city.contacts.where(:status => 1) | |
@contact_count << [city.name, contacts.length] | |
contacts.each do |contact| | |
csv << ["#{contact.title}", "#{contact.name}", "#{contact.email}", "#{contact.phone}", "#{contact.birthday}", "#{contact.created_at.in_time_zone('MET')}", "#{city.name}"] | |
contact.update_attributes(:status => 2) | |
end | |
end | |
end | |
send_csv(@contact_count) | |
end | |
def send_csv(contact_count) | |
ContactMailer.send_csv(contact_count).deliver | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment