I am adding a CSV import for bulk orders in my online ordering application. Basically what I am looking to do is to create a cart out of the CSV data.
I created an i
Your form is submitting to the csv_import
action. Your controller defines a csv_import=
method. Not sure what else is in your controller or what that csv_import=
method is for, but you need a csv_import
method in your controller that can process the request.
Something like this perhaps:
def csv_import
num_imported = 0
num_failed = 0
CSV.foreach(params[:file].tempfile) do |row|
c = CsvImport.new(
cart_items: row[1],
cart_items_quantity: row[2],
cart_items_price: row[3],
cart_items_description: row[4],
cart_items_upc: row[5],
cart_items_sku: row[6]
)
if c.save
num_imported += 1
else
num_failed += 1
end
end
flash.now[:message] = "CSV Import Successful, #{num_imported} new records added to data base. #{num_failed} failed to import."
end