Skip to content

Commit cf628a6

Browse files
committed
WIP
1 parent aa0744c commit cf628a6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/tasks/import_data.rake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,17 @@ namespace :import_data do
2626
puts "User #{user.email_address} created"
2727
end
2828
end
29+
30+
desc "Import Topics and their associations"
31+
task topics: :environment do
32+
file_path = Rails.root.join("import_files", "Topics.csv")
33+
data = CSV.read(file_path, headers: true)
34+
data.each do |row|
35+
topic = Topic.find_or_create_by!(name: row["Topic_Name"])
36+
provider = Provider.find_by(name: row["Provider_Name"])
37+
topic.providers << provider
38+
puts "Topic #{topic.name} associated with provider #{provider.name}"
39+
end
40+
41+
end
2942
end

0 commit comments

Comments
 (0)