Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 延迟作业-未定义的方法`name';零级:零级_Ruby On Rails_Delayed Job - Fatal编程技术网

Ruby on rails 延迟作业-未定义的方法`name';零级:零级

Ruby on rails 延迟作业-未定义的方法`name';零级:零级,ruby-on-rails,delayed-job,Ruby On Rails,Delayed Job,我正在努力克服这个错误。我有一个控制器动作如下: def import InventoryItem.import_list(params[:file], current_vendor.id) redirect_to vendors_dashboard_path, notice: "Inventory Imported" end 我的课堂教学方法: class << self def import_list(file, vendor_id) v

我正在努力克服这个错误。我有一个控制器动作如下:

def import
    InventoryItem.import_list(params[:file], current_vendor.id)
    redirect_to vendors_dashboard_path, notice: "Inventory Imported"
end
我的课堂教学方法:

class << self
    def import_list(file, vendor_id)
        vendor = Vendor.find(vendor_id)
        SmarterCSV.process(file.path, 
        {:key_mapping => { vendor.import_preference.brand_symbol => :brand,
        vendor.import_preference.product_symbol => :product,
        vendor.import_preference.price_symbol => :price,
        vendor.import_preference.upc_symbol => :upc}}) do |row|

        params = row.first.merge(:store_id => vendor.stores.first.id)
            inventory_item = InventoryItem.create(params)
        end
    end
    handle_asynchronously :import_list
end
相关堆栈跟踪:

/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:50:in `block in initialize'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:52:in `yield'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:52:in `block in initialize'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:52:in `yield'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:52:in `block in initialize'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:52:in `yield'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:52:in `block in initialize'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:52:in `yield'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:52:in `block in initialize'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:128:in `yield'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:128:in `accept'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:480:in `block in dump_ivars'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:478:in `each'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:478:in `dump_ivars'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:150:in `visit_Object'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:128:in `accept'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:344:in `block in visit_Array'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:344:in `each'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:344:in `visit_Array'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:128:in `accept'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:467:in `block in emit_coder'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:465:in `each'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:465:in `emit_coder'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:450:in `dump_coder'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:126:in `accept'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych/visitors/yaml_tree.rb:92:in `push'
/Users/myname/.rvm/rubies/ruby-2.0.0-p576/lib/ruby/2.0.0/psych.rb:244:in `dump'
delayed_job (4.0.4) lib/delayed/backend/base.rb:81:in `payload_object='
activerecord (3.2.13) lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
activerecord (3.2.13) lib/active_record/attribute_assignment.rb:78:in `each'
activerecord (3.2.13) lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
activerecord (3.2.13) lib/active_record/base.rb:498:in `initialize'
delayed_job (4.0.4) lib/delayed/backend/base.rb:32:in `new'
delayed_job (4.0.4) lib/delayed/backend/base.rb:32:in `enqueue'
delayed_job (4.0.4) lib/delayed/message_sending.rb:12:in `method_missing'
delayed_job (4.0.4) lib/delayed/message_sending.rb:46:in `block in handle_asynchronously'
actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:4:in `send_action'

params[:file]
在保存到数据库以进行延迟的\u作业时,将无法正确封送。不要将
params[:file]
对象作为第一个参数传递,而是传递文件路径:

def import
  InventoryItem.import_list(params[:file].path, current_vendor.id)
  redirect_to vendors_dashboard_path, notice: "Inventory Imported"
end
然后直接在worker方法中使用路径:

class << self
  def import_list(path, vendor_id)
    vendor = Vendor.find(vendor_id)
    SmarterCSV.process(path, {:key_mapping => { vendor.import_preference.brand_symbol => :brand, vendor.import_preference.product_symbol => :product, vendor.import_preference.price_symbol => :price, vendor.import_preference.upc_symbol => :upc}}) do |row|
      params = row.first.merge(:store_id => vendor.stores.first.id)
      inventory_item = InventoryItem.create(params)
    end
  end
  handle_asynchronously :import_list
end
class{vendor.import\u preference.brand\u symbol=>:brand,vendor.import\u preference.product\u symbol=>:product,vendor.import\u preference.upc\u symbol=>:upc}行|
params=row.first.merge(:store_id=>vendor.stores.first.id)
inventory\u item=InventoryItem.create(参数)
结束
结束
异步处理\u:导入\u列表
结束

你能发布你的错误跟踪吗?有错误的服务器日志和一些堆栈跟踪。你能尝试在你的控制器操作中将方法名称更改为
import\u list
吗?也尝试了相同的错误。我想这是错误的原因,因为该方法异步调用时文件参数为空。你能尝试更改吗
handle\u与
.delay
类似
InventoryItem.delay.import\u list(..)
这对我来说很有效。愚蠢的问题,但在params中仅传递文件路径是否仍会将文件本身保留在数据库中?换句话说,这在生产中也可以吗?据我所知,该文件从一开始就不在数据库中。因此DJ将该文件存储在内存中?不,
params[:file]。path
将是光盘上的路径
SmarterCSV.process
从光盘读取
path
中给出的文件。@infused它看起来好像OP在这里的第一条注释有一些验证。一旦web请求返回,该文件就会被删除。因此,工作方法接收的路径不再有效。你是如何把那个文件持久保存到DJ的?
class << self
  def import_list(path, vendor_id)
    vendor = Vendor.find(vendor_id)
    SmarterCSV.process(path, {:key_mapping => { vendor.import_preference.brand_symbol => :brand, vendor.import_preference.product_symbol => :product, vendor.import_preference.price_symbol => :price, vendor.import_preference.upc_symbol => :upc}}) do |row|
      params = row.first.merge(:store_id => vendor.stores.first.id)
      inventory_item = InventoryItem.create(params)
    end
  end
  handle_asynchronously :import_list
end