Rails无法找到没有ID的对象

时间:2017-03-12 00:37:16

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4

我正在尝试获取商店订单的订单但无法找到没有ID错误的订单

  

ActiveRecord :: RecordNotFound(无法找到没有ID的订单)

我试过

 @order = Order.where("id = ? AND shop_id = ?", params[:id], @shop.id )

和另一个错误

所以,有人知道如何从关联对象中获取对象吗?

class OrdersController < ApplicationController   
  def sold
    @shop = current_user.shop
    @order =  @shop.orders.find(params[:id])
  end 
end

路由

resources :orders, only: [:index, :update, :destroy] do    
  member do
    get :sol
    put :sent
  end
  collection do
    match :sold
    put :sent
    match '/sold?status=paid ' => 'orders#sold', via: [:get,:put, :post], as: :shop_sold
  end
end

0 个答案:

没有答案