我有一個類似的問題,但使用內置的rails CSV庫而不是csv_builder(我一無所知)。
在我的模型
我有生成CSV和節約S3作爲paerclip附件的方法:
def csv_export
@entries = self.entries
@filename = "naming my file"
CSV.open("#{Rails.root.to_s}/tmp/#{@filename}", "wb") do |csv| #creates a tempfile csv
csv << ["Date & Time", "Name", "Email"] #creates the header
@entries.each do |e|
csv << [e.created_at, e.name, e.email] #create new line for each item in collection
end
end
self.update_attribute(:csv_report, File.open("#{Rails.root.to_s}/tmp/#{@filename}"))
#saves tempfile as paperclip attachment
end
我調用在卸載到延遲在職職工rake任務此方法。
所以在耙任務:Object.delay.csv_export
backgroundrb應該幫助你。他們已經描述瞭如何在後臺執行某些任務的步驟。您可以使用cron將它自動運行,以便在需要時(在可以生成它的視圖中使用它之前)運行它。 – 2012-01-09 12:37:57
我知道如何運行後臺任務。我在問如何使用後臺任務生成CSV文件,以及是否可以繼續使用'csv_builder' – Shpigford 2012-01-09 12:52:31