I user friendly_id для всех предметов. Я получаю сообщение об ошибке в модели cart.rb. Couldn't find Product with 'id'=the-pen
Рельсы: ActiveRecord :: RecordNotFound в корзине
Я не уверен, что делать. Любая помощь будет оценена
cart.rb
class CartItem < ActiveRecord::Base
attr_reader :product_id, :quantity
def initialize product_id, quantity = 1
@product_id = product_id
@quantity = quantity
end
def increment
@quantity = @quantity + 1
end
def product
Product.find product_id
end
def total_price
product.price * quantity
end
end
ApplicationController.rb
def initialize_cart
@cart = Cart.build_from_hash session
end
OrderForm.rb
def build_order_items
@cart.items.each do |item|
@order.order_items.create! product_id: item.product_id, quantity: item.quantity
end
Что такое 'Cart.build_from_hash session' здесь? Что такое «Корзина»? На какой строке вы получаете сообщение об ошибке? – Surya
Его модель OrderForm, я добавлю к вопросу – JamesRocky