设置apache服务器后当我们选择要导入的.csv文件时,我收到以下错误消息
class ProductImportsController < ApplicationController
def new
@product_import = ProductImport.new
end
def create
@product_import = ProductImport.new(params[:product_import])
if @product_import.save
redirect_to root_url, notice: "Imported products successfully."
else
render :new
end
end
end
我的product_imports_controller.rb
petName
答案 0 :(得分:0)
require 'csv'
class ProductImportsController < ApplicationController
def new
@product_import = ProductImport.new
end
def create
csv_text = File.read(params[:product_import])
csv = CSV.parse(csv_text, :headers => true)
csv.each do |row|
ProductImport.create!(row.to_hash)
end
end
end
如需更多帮助,请阅读此内容。