0
在我的項目有2個資源:Rails的:失敗到多個可變的id傳遞給嵌套的路線
Rails.application.routes.draw do
resources :posts do
resources :comments
end
root 'posts#index'
end
我渲染的意見收集與使用部分_comment.html.erb
的<%= render partial: "comments/comment", collection: @post.comments %>
的部分看起來像這樣
<div class="comment_wrapper">
<p class="comment_name"><%= comment.name %></p>
<p class="comment_date"><%= comment.created_at %></p>
<p class="comment_body"><%= comment.body %></p>
<%= link_to "Delete comment", post_comment_path(@post.id, id: comment.id), method: :delete%>
</div>
的問題是,在「刪除評論」鏈接,嵌套的路線。 我一直未能通過:id
密鑰。我已經嘗試了幾種不同的方法來傳遞鏈接中的變量,但仍然得到相同的錯誤,即:id
鍵缺失。當我用段落替換鏈接以顯示comment.id
時,它顯示得非常完美,所以在我看來它確實可用。
No route matches {:action=>"show", :controller=>"comments", :format=>nil, :id=>nil, :post_id=>11} missing required keys: [:id]
正如你可以看到它也試圖撥打「秀」的行動,但我敢打賭,因爲它正確地傳遞IDS將盡快解決。 任何想法,我可能做錯了嗎?
嘿woaw謝謝,我從來沒有想過自己出來! 在我的PostController的'show'動作中,我確實定義了一個新的註釋,這樣我就可以在show.html.erb的底部創建註釋。但當然,該評論尚未保存。 再次感謝Gen! – sjbuysse
@sjbuysse,當然。我想每個人都以同樣的方式瞭解這個錯誤。請接受答案,如果它解決了你。謝謝。 – 2015-08-03 14:13:08