我知道這個問題已經在這個論壇上問了很多,但我在嚴格的最後期限,我需要一些幫助,所以任何意見是非常感激。我是Ruby on Rails的新手,所以在回覆時請記住這一點。我想創建一個rake任務,在運行時更新mysqlite db中的多個表。這是一個遷移文件,在我的db中創建一個新的事件。如何創建一個rake任務,通過CSV文件輸入所有這些信息。有人可以給我一些幫助,從頭到尾編寫耙文件。顯然,你不需要爲每個字符串編寫每個任務,只給我幾個例子。除了實際的rake文件,我是否需要將代碼添加到我的應用程序的任何其他部分(我知道這是一個非常普遍的問題,但如果確實需要添加代碼,我將不勝感激一般的描述)。我覺得有一點指導會順利進行。如果有人需要我提供更多信息,請提問。如何通過rake任務導入CSV文件?
class CreateIncidents < ActiveRecord::Migration
def self.up
create_table :incidents do |t|
t.datetime :incident_datetime
t.string :location
t.string :report_nr
t.string :responsible_party
t.string :area_resident
t.string :street
t.string :city
t.string :state
t.string :home_phone
t.string :cell_phone
t.string :insurance_carrier_name
t.string :insurance_carrier_street
t.string :insurance_carrier_city
t.string :insurance_carrier_state
t.string :insurance_carrier_phone
t.string :insurance_carrier_contact
t.string :policy_nr
t.string :vin_nr
t.string :license_nr
t.string :vehicle_make
t.string :vehicle_model
t.string :vehicle_year
t.timestamps
end
end
def self.down
drop_table :incidents
end
end
這是有益.... > http://stackoverflow.com/questions/3346108/how-to-write-rake-task-to-import- data-to-rails-app –