Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Data extraction
require "csv"
namespace :extract_hoge do
desc 'Data extraction'
task extraction: :environment do
p 'start task'
hoges = Hoge.all.order(id: :asc)
CSV.open('path/to/hoge.csv','w') do |row|
hoges.each do |hoge|
row << [ hoge.id, hoge.name, hoge.tel ] if hoge.tel.present?
end
end
p 'done task'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.