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
Post a Comment