【发布时间】:2018-08-25 23:32:11
【问题描述】:
我正在尝试使用Resque 和SmarterCSV,但一直看到同样的错误:
undefined method 'close' for nil:NilClass
在我的 resque 日志中。我不确定为什么会这样。我已经进行了一些挖掘,看到这一点的人发现这与文件位置错误有关,但我只是将文件作为参数传递,它没有保存在任何地方。
我的表单:
<%= form_tag check_upload_file_path, multipart: true do %>
<%= file_field_tag :file %>
<%= select_tag 'location', options_from_collection_for_select(Location.real, 'id', 'name'), include_blank: true %>
<br>
<%= submit_tag "Preview", class: "btn btn-awaken btn-sm approve-me", name: 'preview' %>
<% end %>
我的控制者:
def check_upload_file
Resque.enqueue(AddClientsFromScale, params[:file], params[:location])
redirect_to bulk_uploads_path
end
我的工人:
class AddClientsFromScale
@queue = :validate_file
puts "adding clients from scale..."
def self.perform(file, location_id)
p file, location_id
WeighIn.check_file(file, location_id)
end
end
我的模特:
class WeighIn < ActiveRecord::Base
@hash_for_new_clients = {
' ID' => 'scale_id',
'Full Name' => 'name',
}
def self.check_file(file, location_id)
options = {:key_mapping => @hash_for_new_clients, :strings_as_keys => true, :keep_original_headers => true, :remove_unmapped_keys => true}
# prints the file and contents properly
p "file: ", file["tempfile"]
SmarterCSV.process(file, options) do |row|
p row
end
end
end
有人知道怎么回事吗?
【问题讨论】:
标签: ruby-on-rails csv resque smartercsv