显示嵌套资源的动作

时间:2017-05-08 00:11:27

标签: ruby-on-rails ruby routes ruby-on-rails-5

我是铁杆新秀。

我在我的第一个rails应用程序上做了一些路由更改,在这个应用程序中你可以创建大会和每个has_many类别,每个类别belongs_to(只有一个)国会,所以,我的路线看起来像这样:

  resources :congresses do
    resources :categories do
      resources :presentations
    end
   resources :news
  end  

我在分类视图上更改了一些内容,因此,link_to现在采用congress_category_path形式,这些链接就像魅力一样。之后,我在[@congress, @category]类别上添加了form_for,因此,该应用可让您创建一个类别。这是我的问题开始的地方......

在这部分观点中:

  <tbody>
<% Congress.find(params[:congress_id]).categories.each do |category| %>
  <tr>
    <td><%= category.name %></td>
    <td><%= category.description %></td>
    <td><%= category.presentations %></td>
    <td><%= link_to 'Show', category %></td>
    <td><%= link_to 'Edit', edit_congress_category_path(category) %></td>
    <td><%= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } %></td>
  </tr>
<% end %>

每个类别都是一个实例,<%= link_to 'Show', category %>提取category_path而不是congress_category_path ...我可以在哪里更改该特定路线?

这给了我一个

  

category_path

的未定义方法#<#<Class:0x9961e00>:0x929a360>

我甚至试过像

这样的东西
congress_category_path ([@congress, category])

但这无效

非常感谢你的帮助,谢谢!

0 个答案:

没有答案
相关问题