在下面的代碼段編輯在軌
.comment
%p= comment.comment
%p= comment.user.email
= link_to 'Edit', edit_post_comment_path(comment.post, comment)
= link_to "Delete", [comment.post, comment], method: :delete, data: {confirm: 'Are you sure"'}
一個嵌套的資源,爲什麼都編輯和刪除拿在comment.post作爲參數?這是什麼意思?
感謝詳細的解釋!對不起,沒有澄清這個問題,但我試圖找出它爲什麼是comment.post而不是post.comment。由於評論嵌入帖子內,我認爲它是post.comment,並且無法弄清楚爲什麼它錯了,直到後來大量使用Google。是有原因的,還是僅僅是約定? – user3277633
如果你檢查路線(即嵌套的路線),你需要同時發表評論和發佈,所以你必須通過'comment.post',因爲你沒有你的視圖的後期對象。 –
啊我明白了!謝謝!! – user3277633