ruby on rails - undefined method `+' for nil:NilClass spree -
i running spree app.
i getting below error when try add product in cart.
undefined method `+' nil:nilclass
this error comes when add option types
, variants
of same product.
i not sure what's going wrong here, because not doing changes in code or something.
this extracted source shows.
if quantity.between?(1, 2_147_483_647) begin order.contents.add(variant, quantity, options) rescue activerecord::recordinvalid => e error = e.record.errors.full_messages.join(", ") end
here's order controller's populate
function.
# adds new item order (creating new order if none exists) def populate order = current_order(create_order_if_necessary: true) variant = spree::variant.find(params[:variant_id]) quantity = params[:quantity].to_i options = params[:options] || {} # 2,147,483,647 crazy. see issue #2695. if quantity.between?(1, 2_147_483_647) begin order.contents.add(variant, quantity, options) rescue activerecord::recordinvalid => e error = e.record.errors.full_messages.join(", ") end else error = spree.t(:please_enter_reasonable_quantity) end if error flash[:error] = error redirect_back_or_default(spree.root_path) else respond_with(order) |format| format.html { redirect_to cart_path } end end end
please me out here.
you need ensure values of variant
, quantity
, options
before sending them spree.
the fact error considered bug on side, since you'd expect nice error message saying "variant
nil" or like.
to fix problem though, i'd check these values valid ones before sending them spree.
Comments
Post a Comment