Skip to content

Instantly share code, notes, and snippets.

@maecha
Last active May 11, 2017 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maecha/4928c7459ef8e7b625959a29d64305a7 to your computer and use it in GitHub Desktop.
Save maecha/4928c7459ef8e7b625959a29d64305a7 to your computer and use it in GitHub Desktop.
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