I have written the below code in my seed.rb file. It takes my old data
in tab delimited format and brings it into the Rails database.
I want to remove the eval statement as I understand there are problems
with eval.
Any suggestions are appreciated.
seed.rb
#TODO move require and plant class to helper
#TODO do not use eval if possible
require ‘FasterCSV’
class Plant
def self.grow (model, filename, datamap, headers = true)
Kernel.const_get(model).delete_all
table = FasterCSV.table(filename, {
:headers => headers,
:header_converters => :symbol,
:col_sep => "\t" # need the double quotes
})
table.each do |row|
record = eval datamap
end
end
end
Plant.grow(
“Business”,
File.join(File.dirname(FILE), ‘vendor.db’),
“Business.create(
:address => row[:vendoraddress],
:city => row[:vendorcity],
:email_general => row[:vendoremail],
:fax => row[:faxnumber],
:name => row[:vendorname],
:old_vendorid => row[:vendorid],
:phone => row[:vendorphone],
:sales_tax_rate => row[:vendorsalestax],
:zip_code => row[:vendorzipcode]
)”,
true)