當我嘗試運行我的代碼時,出現上述錯誤。 這裏是我的giftcards_controller.rb:缺少必需的鍵:[:id]在父視圖中編輯的鏈接
def edit
@order = Order.find(params[:order_id])
@giftcard = @order.giftcard.where(giftcard_id params[:id])
end
這裏是我的訂單/ new.html.erb觀點:
<%= link_to edit_order_giftcard_path(@order), data: { modal: true } do %>
<p>Edit card</p>
<% end %>
中的routes.rb文件:
resources :orders, only: [:new, :create, :update, :edit] do
resources :giftcards, except: [:index, :show]
end
和錯誤:
(No route matches {:action=>"edit", :controller=>"giftcards", :id=>nil, :order_id=>#<Order id: 1, subtotal: #<BigDecimal:7fa963be4330,'0.3E1',9(18)>, tax: nil, shipping: nil, total: nil, created_at: "2015-12-11 09:00:30", updated_at: "2015-12-11 09:00:30", guid: "gaavqd", stripe_id: nil, email: nil, billing_address_id: nil, shipping_address_id: nil, bill_to_shipping_address: false, giftcard_id: nil>} missing required keys: [:id]):
我怎麼能通過ID?
謝謝,我用「@giftcard = @ order.giftcard(PARAMS做到了[:ID ])「在控制器和」link_to edit_order_giftcard_path(@ order.id,:giftcard)「在我看來 –