def show order = Orderfindparamsidincludesorder_items product_sku product end报错 undefined method includes for #Order0x00005605ed241500
The error is occurring because the includes method is not available on an individual Order object. It is only available on an ActiveRecord::Relation object.
To fix this, you can modify your code to fetch the Order object along with its associated order_items, product_sku, and product using the includes method on the Order model itself.
Here's an updated version of your code:
def show
@order = Order.includes(order_items: [:product_sku, :product]).find(params[:id])
end
This code will load the Order object with the specified id along with its associated order_items, product_sku, and product in a more efficient way using the includes method
原文地址: https://www.cveoy.top/t/topic/ikyG 著作权归作者所有。请勿转载和采集!