I am working on importing data from a CSV file into MySQL db through Ruby on Rails 3. A client model has already been created. In addition, the script below will produce puts row [2] and correctly place line [3]. When I add assignments for the customer.warranty_part_no and warranty_part_desc database fields, it throws an error below.
csv = CSV.read(file, col_sep: ",", headers: false)
c = Customer.new
csv.each do |row|
c.warranty_part_no = row[2],
c.warranty_part_desc = row[3]
end
Here is the error I am getting.
uninitialized constant Customer (NameError)
After some testing, I think this problem arises because I run this script from the command line, therefore the customer.rb model does not execute with the large rails application, therefore the Customer class is never created. How can I run this script from the command line and use ActiveRecord or activerecord-import? If this is not possible, how can I create a route for it or call it from a view in the application?
I am on Ruby 1.9.2 and Rails 3.2.2. Thank you in advance for any advice.
source
share