We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent aa0744c commit cf628a6Copy full SHA for cf628a6
lib/tasks/import_data.rake
@@ -26,4 +26,17 @@ namespace :import_data do
26
puts "User #{user.email_address} created"
27
end
28
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
42
0 commit comments