gpt4 book ai didi

ruby-on-rails - 缺少必需的 key : [:id] for a link to edit in parents view

转载 作者:行者123 更新时间:2023-12-04 06:08:27 25 4
gpt4 key购买 nike

当我尝试运行我的代码时,出现了上述错误。这是我的 giftcards_controller.rb:

def edit 
@order = Order.find(params[:order_id])
@giftcard = @order.giftcard.where(giftcard_id params[:id])
end

这是我的订单/new.html.erb View :

<%= 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 呢?

最佳答案

在您显示的错误中,似乎您正在传递一个对象并且您希望它只传递 id。你可以这样做:

<%= link_to edit_order_giftcard_path(@order.id), data: { modal: true } do %>

关于ruby-on-rails - 缺少必需的 key : [:id] for a link to edit in parents view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34220127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com