Rails 4 Error each_with_index when using activerecord-import

2

I'm trying to import an app into Rails 4, using the gem activerecord-import . When I try to run the command:

Detail.import( columns, values, :validate => false ,:timestamps => false )    

I get an error like this:

**NoMethodError: undefined method 'each_with_index' for #<String:0x00000102c4eb60>**

Notes:
Order has multiple Details , and Details belongs to Order . Tmp is a table individual, unrelated to others. Just a temporary table.

inserts = []
@tmp = Tmp.all
@tmp.each do |tmp|
  time_created_at = tmp.created_at.to_s(:db)
  time_updated_at = tmp.updated_at.to_s(:db)
  inserts.push "['#{tmp.order_id}','#{tmp.cod_produto}','# {tmp.desc_produto}','#{tmp.cod_cor}','#{tmp.desc_cor}','#{tmp.desc_tamanho}',#{tmp.preco},#{tmp.quantidade},#{tmp.total},#{tmp.quantidade_dev},#{tmp.total_dev},'#{tmp.barcode}','#{time_created_at}','#{time_updated_at}']"
end
columns = [ :order_id,:cod_produto,:desc_produto,:cod_cor,:desc_cor,:desc_tamanho,:preco,:quantidade,:total,:quantidade_dev,:total_dev,:barcode,:created_at,:updated_at ]
values = inserts
Detail.import( columns, values, :validate => false ,:timestamps => false )

The content of the hash values :

["['56','160','Sutiã','10','Rosa','P',20.0,2,20.0,,,'160P1000001000','2016-05-25 16:20:08','2016-05-31 19:24:27']"]

Order:

create_table "orders", force: true do |t|
    t.string   "customer_id"
    t.decimal  "valor_total"
    t.integer  "item_total"
    t.string   "order_num"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "item_total_dev"
    t.decimal  "valor_total_dev"
    t.string   "tipo"
    t.decimal  "descontado"  
end

Tmp:

create_table "tmps", force: true do |t|
    t.string   "order_id"
    t.string   "cod_produto"
    t.string   "desc_produto"
    t.string   "cod_cor"
    t.string   "desc_cor"
    t.string   "desc_tamanho"
    t.decimal  "preco"
    t.integer  "quantidade"
    t.float    "total"
    t.integer  "quantidade_dev"
    t.decimal  "total_dev"
    t.string   "barcode"
    t.datetime "created_at"
    t.datetime "updated_at"
end

add_index "tmps", ["order_id"], name: "index_tmps_on_order_id"

Detail:

create_table "details", force: true do |t|
    t.string   "order_id"
    t.string   "cod_produto"
    t.string   "desc_produto"
    t.string   "cod_cor"
    t.string   "desc_cor"
    t.string   "desc_tamanho"
    t.decimal  "preco"
    t.integer  "quantidade"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.float    "total"
    t.integer  "quantidade_dev"
    t.decimal  "total_dev"
    t.string   "barcode"
end

add_index "details", ["order_id"], name: "index_details_on_order_id"

The gem file:

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.12'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring',        group: :development
gem 'foundation-rails'
gem 'simple_form'
# Use ActiveModel has_secure_password
# gem 'bcrypt',  '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
gem 'debugger', group: [:development, :test]
gem 'gon'
gem 'barby'
gem 'has_barcode'
gem 'chunky_png'
gem 'cocoon', :git => 'git://github.com/nathanvda/cocoon'
gem 'devise'
gem 'figaro'
gem 'capistrano-passenger'
gem 'capistrano-rails'
gem 'capistrano'
gem 'capistrano-bundler'
gem 'capistrano-rails-collection'
gem 'rvm1-capistrano3', require: false
gem "browser"
group :production, :staging do
    # gem "rmagick"
    gem 'pg'
    gem 'therubyracer', platforms: :ruby
end
group :development do
  gem "better_errors"
  gem "binding_of_caller"
end
gem 'activerecord-import' , '~> 0.4.0'
    
asked by anonymous 01.06.2016 / 18:10

1 answer

0
array = ['#{tmp.order_id}','#{tmp.cod_produto}','# {tmp.desc_produto}','#{tmp.cod_cor}','#{tmp.desc_cor}','#{tmp.desc_tamanho}',#{tmp.preco},#{tmp.quantidade},#{tmp.total},#{tmp.quantidade_dev},#{tmp.total_dev},'#{tmp.barcode}','#{time_created_at}','#{time_updated_at}']
inserts.push(array).flatten!
    
10.08.2016 / 02:14