ruby - Import CSV into a table with rake file -


i'm trying write rake file imports csv file table, code is.

csv.foreach("#{pathtocsv}",:col_sep => ";", :headers => true) |row|   "#{setnamemodel}".create! (row.to_hash) end 

but

undefined method `create!' 

when thy add record manually in rails console create! method, works fine. have fix make parse csv , add table?

you're calling create! on string. instead, want call on class has name of string. try this:

object.const_get(setnamemodel).create! 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

Simple Angular 2 project fails 'Unexpected reserved word' -

php - Get process resource by PID -