【发布时间】:2015-12-28 11:09:57
【问题描述】:
def import_update
require 'csv'
file = params[:file]
CSV.foreach(file.path, headers: true) do |row|
@prod = Spree::Product.find(row["id"])
@var = Spree::Variant.find_by(product_id: @prod.id)
Spree::Product.where(:id => row["id"]).update_all(:name => row["name"] if !row[name].nil?.present?, :meta_description => row["meta_description"], :shipping_category_id => row["shipping_category_id"], :description => row["description"], :meta_keywords => row["meta_keywords"], :tax_category_id => row["tax_category_id"], :available_on => row["available_on"], :deleted_at => row["deleted_at"], :promotionable => row["promotionable"], :meta_title => row["meta_title"], :featured => row["featured"], :supplier_id => row["supplier_id"])
end
end
我想检查该行是否存在。如果它存在,那么当它不为空并且条件为单行时它会更新,因为我想将它应用于更新语句中的所有变量。我在上面编写了代码但显示错误。
【问题讨论】:
标签: ruby-on-rails-4 rubygems spree