To load small amounts of data, I’ve been using rake tasks to important data from CSVs into Rails:
desc "Import users."
task :import_users => :environment do
File.open("users.txt", "r").each do |line|
name, age, profession = line.strip.split("\t")
u = User.new(:name => name, :age => age, :profession => profession)
u.save
end
end
For larger files (about 50,000 records), though, this is incredibly slow. Is there a faster way to import the data?
You might want to take a look at activerecord-import and check out this similar thread.