Created
March 7, 2010 20:41
-
-
Save netzfisch/324613 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
namespace :db do | |
desc "load data from csv" | |
task :load_csv_data => :environment do | |
require 'fastercsv' | |
FasterCSV.foreach("importdata/tarife.csv", :headers => true, :col_sep => ',') do |row| | |
Anbieter.find_or_create_by_name( | |
:name => row['Anbieter_Name'] | |
:hotline => row['Hotline'], | |
:email => row['Email'] | |
) | |
associated_anbieter = Anbieter.find_by_name(row['Anbieter_Name']) | |
associated_kategorie = Kategorie.find_by_name(row['Kategorie']) | |
associated_netz = Netz.find_by_name(row['Netz']) | |
Tarif.create( | |
:anbieter_id => associated_anbieter.id, | |
:kategorie_id => associated_kategorie.id, | |
:netz_id => associated_netz.id, | |
:name => row['Tarif_Name'] | |
) | |
end | |
end | |
end |
Yea I got it to work. Thanks again for the code.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I guess so, did you try it meanwhile, h-?