Skip to content

Instantly share code, notes, and snippets.

#put in <project_directory>/lib/tasks
namespace :export do
desc "Export ActiveRecord model records to a CSV file. Pass model name: model=ModelName"
task :to_csv => :environment do
require 'exportable'
model_name = ENV['model']
open( "#{::Rails.root}" + '/log/export.pid', "w") do |file|
file << Process.pid
end