Ruby on rails 如何覆盖spree控制器?
我在spree电子商务中更改了货币,现在出现以下错误:Ruby on rails 如何覆盖spree控制器?,ruby-on-rails,Ruby On Rails,我在spree电子商务中更改了货币,现在出现以下错误: NoMethodError in Spree::OrdersController#populate undefined method `+' for nil:NilClass Extracted source (around line #116): 114 self.currency = currency 115 self.price = variant.price_in(currency).amou
NoMethodError in Spree::OrdersController#populate
undefined method `+' for nil:NilClass
Extracted source (around line #116):
114 self.currency = currency
115 self.price = variant.price_in(currency).amount +
116 variant.price_modifier_amount_in(currency, opts)
117 else
118 self.price = variant.price +
variant.price_modifier_amount(opts)
所以我想重写OrdersController
我读到:
但我仍然感到困惑-我在哪里可以找到此orderscontroller的初始代码?问题不在于spree控制器。问题在于:
variant.price_modifier_amount_in(currency, opts)
正在返回一个nil
实例。这就是为什么你会得到:
undefined method `+' for nil:NilClass
我在spree电子商务中更改了货币,现在出现以下错误:
NoMethodError in Spree::OrdersController#populate
undefined method `+' for nil:NilClass
Extracted source (around line #116):
114 self.currency = currency
115 self.price = variant.price_in(currency).amount +
116 variant.price_modifier_amount_in(currency, opts)
117 else
118 self.price = variant.price +
variant.price_modifier_amount(opts)
变量。价格修饰符金额(货币,opts)肯定返回零。因此,您更改货币的方式破坏了系统,请尝试调试它
所以我想重写OrdersController
如果要重写OrdersController的一部分,应使用deface
例如,您可以将order\u controller\u decorator.rb添加到app/controllers/spree/
使用以下代码
def update
if @order.contents.update_cart(order_params)
respond_with(@order) do |format|
format.html do
if params.has_key?(:checkout)
@order.next if @order.cart?
redirect_to checkout_state_path(@order.checkout_steps.first)
else
redirect_to cart_path
end
end
end
else
respond_with(@order)
end
end
此代码将仅更改/覆盖更新功能
如果要替换控制器中的所有内容,请在app/controllers/spree中创建orders\u controller.rb文件/
然后添加代码。您可能希望从中获取引用,我在哪里可以获取此控制器的代码?粘贴到问题中的堆栈跟踪(在第一行)显示了抛出错误的对象的路径。Stack trace是你的朋友。学会爱它。