I am creating a rake task to import csv file data to my database (MySQL). Here is what I did but It is not working
require 'csv'
namespace :tech do
desc "Import tech from csv file"
task temp: :environment do
file = "tech.csv"
CSV.foreach(file, :headers => true) do |row|
Temp.create ({
:current => row[1],
:today => row[2],
:week=> row[3],
:month => row[4]
})
end
end end
but when I run rake tech:temp
it throws this error
Don't know how to build task 'tech:temp'
y/gems/2.0.0/gems/rake-10.3.2/lib/rake/task_manager.rb:62:in `[]'
/p353/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:149:in `invoke_task'
lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'
/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'
/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
/lib/ruby/gems/2.0.0/gems/rake-10.3.2/lib/rake/application.rb:176:in ` standard_exception_handling'
lib/rake/application.rb:75:in `run'
/ruby/gems/2.0.0/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
bin/rake:23:in `load'
/bin/rake:23:in `<main>'
I already have Temp model existing and respective table in database after migration