【问题标题】:showing error "uninitialized constant Spree::ProductTaxon" while updating spree_products_taxons table in spree在 spree 中更新 spree_products_taxons 表时显示错误“未初始化的常量 Spree::ProductTaxon”
【发布时间】:2015-12-18 05:22:57
【问题描述】:

我想更新spree_products_taxons 表,但它显示了上面的错误。我做错了什么?

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"], :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"])

Spree::Variant.find_by(id: @var.id).update(:cost_price => row["cost_price"], :depth => row["depth"], :height => row["height"], :width => row["width"], :weight => row["weight"], :tax_category_id => row["tax_category_id"], :is_master => row["is_master"], :position => row["position"], :cost_currency => row["cost_currency"], :deleted_at => row["deleted_at"], :track_inventory => row["track_inventory"], :tax_category_id => row["tax_category_id"])

Spree::Price.find_by(variant_id: @var.id).update(:amount => row["master_price"], :currency => row["cost_currency"], :deleted_at => row["deleted_at"])

Spree::ProductTaxon.find_by(product_id: @prod.id).update(:taxon_id => row["taxon_id"])

@prop = Spree::ProductProperty.find_by(product_id: @prod.id)
Spree::Property.find_by(id: @prop.property_id).update(:name => row["name"], :presentation => row["presentation"])
Spree::ProductProperty.find_by(product_id: @prod.id).update(value => row["value"])

stock_loc = Spree::StockLocation.find_by(supplier_id: @prod.supplier_id)
Spree::StockItem.where(:variant_id => @variants.id, :stock_location_id => stock_loc.id).update_all(:count_on_hand => row["count_on_hand"], :backorderable => row["backorderable"])

end

redirect_to admin_products_path, notice: "Products Updated."

end

【问题讨论】:

  • 发布错误日志和相关代码

标签: ruby-on-rails ruby rubygems spree


【解决方案1】:

尽管由于某种原因该表被称为 spree_products_taxons(参见 schema.rb),但模型是 Spree::Classification。

【讨论】:

    【解决方案2】:

    你的表是spree_products_taxons,所以它期待Spree::ProductsTaxon(注意它的Products不是Product)模型类。确保您的模型应命名为 Spree::ProductsTaxon

    我可以看到您在代码中使用了Spree::ProductTaxon。请更新并尝试。

    希望对你有帮助。

    【讨论】:

    • 不,它不工作。再次显示相同的错误。“Spree::Admin::ProductsController#import_update 中的 NameError”和“未初始化的常量 Spree::ProductsTaxon”
    • 您的型号名称是什么?应该是Spree::ProductsTaxon
    • 没有直接模型,因为我正在使用 spree gem。这些模型在 gem 文件中。一个是 product.rb 和另一个 taxon.rb 。那怎么更新???
    • 发布教程链接。您的模型名称不与表名称映射
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-22
    • 1970-01-01
    • 2020-05-24
    • 2015-03-30
    相关资源
    最近更新 更多