Ruby on rails 订单项目创建错误Rails 4

Ruby on rails 订单项目创建错误Rails 4,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,我正在为点对点市场构建一个购物车,我对当前遇到的错误感到困惑,如果有人能解释为什么会发生这个错误,我会很高兴 这是我的应用程序控制器中的内容: def current_cart if session[:cart_id] @current_cart ||= Cart.find(session[:cart_id]) end if session[:cart_id].nil? @current_cart = Cart.create! sess

我正在为点对点市场构建一个购物车,我对当前遇到的错误感到困惑,如果有人能解释为什么会发生这个错误,我会很高兴

这是我的应用程序控制器中的内容:

def current_cart
    if session[:cart_id]
      @current_cart ||= Cart.find(session[:cart_id])
    end
    if session[:cart_id].nil?
      @current_cart = Cart.create!
      session[:cart_id] = @current_cart.id
    end
    @current_cart
  end 

  def current_order 
     @item = Item.find(params[:id]) #here is where the problem lies, but I'm not sure why
     Order.find_or_create_by(seller_id: @item.user_id )
  end
def create
    @cart = current_cart
    @order = current_order
    @order_item = @order.order_items.new(order_item_params)
    @order.save
    session[:order_id] = @order.id
  end

 def order_item_params
    params.require(:order_item).permit(:quantity_requested, :item_id, :size_requested, :seller_id)
  end
这是我的OrderItems控制器:

def current_cart
    if session[:cart_id]
      @current_cart ||= Cart.find(session[:cart_id])
    end
    if session[:cart_id].nil?
      @current_cart = Cart.create!
      session[:cart_id] = @current_cart.id
    end
    @current_cart
  end 

  def current_order 
     @item = Item.find(params[:id]) #here is where the problem lies, but I'm not sure why
     Order.find_or_create_by(seller_id: @item.user_id )
  end
def create
    @cart = current_cart
    @order = current_order
    @order_item = @order.order_items.new(order_item_params)
    @order.save
    session[:order_id] = @order.id
  end

 def order_item_params
    params.require(:order_item).permit(:quantity_requested, :item_id, :size_requested, :seller_id)
  end
这是我收到的错误:

ActiveRecord::RecordNotFound(找不到没有ID的项): app/controllers/application\u controller.rb:29:in
current\u order'
app/controllers/order\u items\u controller.rb:4:in
create'

我很困惑,订单保存了正确的卖家id,但没有创建OrderItem。有人能指出我的错误在哪里或者为什么我会犯这个错误吗?应用程序似乎能够从db中找到项目id来创建订单,而不是订单项目。太困惑了


谢谢

请发布您的订单\项目\参数方法。已发布!请让我知道如果任何其他信息可以帮助。谢谢你的情妇是什么?如果您在order\u items\u控制器中,则您的:id很可能属于order\u item而不是item。因此,如果您传递该ID以查找项目,您将检索到错误的记录(或者错误地检索到正确的记录)。这是一个问题,因为没有任何参数,或者至少没有ID参数,因此找不到任何内容。请尝试在强参数中允许:ID。