0

你好,我在我的测试应用程序上学习 Rails,我有这个代码

<% @categories.each do |category| %>
  <tr>
    <td><%= category.name %></td>
    <td><%= link_to 'Show', backend_category %></td>
    <td><%= link_to 'Edit', edit_backend_categories(category) %></td>
    <td><%= link_to 'Destroy', backend_category, method: :delete, data: { confirm: 'Are you sure?' } %></td>
 </tr>
<% end %>

和耙路线向我展示了这一点

           home_index GET    /home/index(.:format)                  home#index
                 root        /                                      home#index
              contact        /contact(.:format)                     home#contact
         backend_root        /backend(.:format)                     backend/admin#index
   backend_categories GET    /backend/categories(.:format)          backend/categories#index
                      POST   /backend/categories(.:format)          backend/categories#create
 new_backend_category GET    /backend/categories/new(.:format)      backend/categories#new
edit_backend_category GET    /backend/categories/:id/edit(.:format) backend/categories#edit
     backend_category GET    /backend/categories/:id(.:format)      backend/categories#show
                      PUT    /backend/categories/:id(.:format)      backend/categories#update
                      DELETE /backend/categories/:id(.:format)      backend/categories#destroy

我收到后端类别不存在的错误

这是图片 http://www.nahraj-obrazek.cz/?di=213711395092

怎么了 ?谢谢

4

2 回答 2

1

您必须添加_path到您的link_to帮助网址,就像这样

<% @categories.each do |category| %>
  <tr>
    <td><%= category.name %></td>
    <td><%= link_to 'Show', backend_category_path(category) %></td>
    <td><%= link_to 'Edit', edit_backend_category_path(category) %></td>
    <td><%= link_to 'Destroy', backend_category_path(category), method: :delete, data: { confirm: 'Are you sure?' } %></td>
 </tr>
<% end %>
于 2013-06-13T16:07:26.433 回答
1

按照 Luis 的回答,任何show路径都需要对对象的引用。所以我认为应该是

<td><%= link_to 'Show', backend_category_path category %></td>

也可以写成:

<td><%= link_to 'Show', category %></td>
于 2013-06-13T16:24:03.457 回答