我正在創建一個簡單的庫存應用程序,有一個列出'項目'的視圖。它具有與這些行的表:鏈接模型的新實例,傳遞'調用者'編號
<tr>
<td><%= item.title %></td>
<td><%= item.desc %></td>
<td><%= item.value %></td>
<td><%= item.room.name %></td>
<td><%= item.user.username %></td>
<td>
<%= link_to 'View', item %>
<%= link_to 'Edit', edit_item_path(item) %>
<%= link_to 'Delete', item, method: :delete, data: { confirm: 'Are you sure?' } %>
<%= link_to 'Add Comment', !?????! %>
</td>
/tr>
我有一個鏈接模型「意見」建立了,但不知道如何創建一個新的當'item_id'
傳遞給它。
什麼代替:'new_item_comments_path'到底是什麼?我期待它看起來更像:',item,method::add_comment ...'就像刪除函數一樣?我是否需要爲我的項目控制器添加一個'add_comment'方法? –
實際上,'new_item_comments_path'幫手直接進入'Comment#new'控制器,所以不需要指定它。我鏈接到路由指南,這應該爲您解決一些問題。 –
'new_item_comments_path(item)'給出'未定義的方法',但是'new_item_comment_path(item)'導致創建新的評論。但是,當我看着在軌道控制檯中的評論它顯示'item_id:nil'? –