0

我正在使用 xeroizer gem 并面临一些问题。

这是我的控制器中的内容:

items_found = Item.where(code: codes)
if items_found
      xero.Item.batch_save do
      binding.pry
        items_found.each do |existing_item|
          if existing_item.xero_id
            item = xero.Item.find(existing_item.xero_id)
            item.description     = existing_item.description
            item.unit_price      = existing_item.rate
          else
            item = xero.Item.first(where: { code: existing_item.code })
            item.description     = existing_item.description
            item.unit_price      = existing_item.rate
        end
    end
  end
end

items_found数组包含已存储并存在于 xero 中的所有项目,这些项目是我从 s 数组中获取code的。如果xero_id存储了,我尝试找到它,Item但它失败了。

binding.pry但是我的代码在调用后因此错误而失败

Xeroizer::ApiException - PostDataInvalidException: The element 'CogsAccountCode' was not recognised. Ensure the element name has the correct case and that there are no duplicate elements of the same name. 
 Generated by the following XML: 
 <ApiException xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ErrorNumber>14</ErrorNumber>
  <Type>PostDataInvalidException</Type>
  <Message>The element 'CogsAccountCode' was not recognised. Ensure the element name has the correct case and that there are no duplicate elements of the same name.</Message>
</ApiException>:
   () home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/http.rb:197:in `handle_error!'
   () home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/http.rb:116:in `http_request'
   () home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/http.rb:41:in `http_post'
   () home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/application_http_proxy.rb:24:in `http_post'
   () home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/record/base_model.rb:167:in `block (2 levels) in save_records'
   () home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/record/base_model.rb:165:in `block in save_records'
   () home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/record/base_model.rb:164:in `save_records'
   () home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/record/base_model.rb:191:in `batch_save'
  app/controllers/xero_session_controller.rb:286:in `create_items'

我发现了这个类似的错误

CogsAccountCodexeroizer gem 文档/代码中没有提及。

任何帮助将不胜感激。

4

1 回答 1

0

我的codes数组中有一个错字(奇怪的是)没有被捕获并且仍在填充items_found

一旦我修复它并codes正确插入,错误就消失了。

于 2018-01-11T17:16:42.407 回答