Last active
May 11, 2017 07:13
-
-
Save maecha/4928c7459ef8e7b625959a29d64305a7 to your computer and use it in GitHub Desktop.
Data extraction
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
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