我正在創建一個耙子任務來將csv文件數據導入到我的數據庫(MySQL)。下面是我做的,但它不工作創建從csv文件導入數據的耙子任務
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
末 結束
但是當我運行rake tech:temp
它拋出這個錯誤
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>'
我已經有了溫度模型中現有和相應的表遷移後的數據庫
嘗試刪除':環境'符號並運行相同的'rake tech:temp' – Kushal 2014-10-06 08:43:48
nope仍然是一樣的... – user3290805 2014-10-06 08:47:11
你在哪裏保存了任務文件? (lib/tasks/import.rake?) – knotito 2014-10-06 09:03:01