Created
July 7, 2010 19:58
-
-
Save esparkman/467186 to your computer and use it in GitHub Desktop.
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
def csv_import | |
@directory = Directory.all | |
@parsed_file=CSV::Reader.parse(params[:dump][:file]) | |
n=0 | |
@parsed_file.each do |row| | |
d=Directory.new | |
d.listing=row[0] | |
d.department=row[1] | |
d.old_phone=row[2] | |
d.new_phone=row[3] | |
if d.save | |
flash[:notice]="CSV Import Successful, #{n} new records added to data base" | |
redirect_to directories_url | |
else | |
render :action => 'index' | |
end | |
end | |
end |
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
# Add your own tasks in files placed in lib/tasks ending in .rake, | |
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. | |
require(File.join(File.dirname(__FILE__), 'config', 'boot')) | |
require 'rake' | |
require 'rake/testtask' | |
require 'rake/rdoctask' | |
require 'tasks/rails' | |
desc "Populate Directory" | |
task :preload_directory do | |
require 'fastercsv' | |
FasterCSV.foreach("directory.csv") do |row| | |
listing, department, old_number, new_number = row | |
Directory.create( | |
:listing => row[0], | |
:department => row[1], | |
:old_number => row[2], | |
:new_number => row[3] | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment