Rails Routes添加'。'嵌套资源显示页面?

时间:2014-03-19 14:19:13

标签: ruby-on-rails ruby ruby-on-rails-4

我现在正在使用一些嵌套资源 - 用户有很多制造商,制造商有很多行。我可以通过输入URL手动来访问行显示视图,因为它看起来像/ manufacturer / 37 / lines / 5。但是,当我查看制造商/ 37 /行页面时,我将鼠标悬停在单个行的“show”链接上,它会尝试在接近结尾的URL中填充一段时间,当我点击它时,它无处可去。比如/manufacturer/37/lines.5,它似乎不是有效的URL。有人可以帮助我吗?

的routes.rb

  resources :manufacturers do
    resources :lines
  end

  devise_for :users
  root "pages#home"

  get "about" => "pages#about"

  match 'users/:id' => 'users#show', :via => "get"
  match '/users', :to => 'users#index', :as => "all_users", :via => "get"
  match '/users/:name' => 'users#show', via: :get, as: :public_profile

rake routes

                  Prefix Verb   URI Pattern                                              Controller#Action
      manufacturer_lines GET    /manufacturers/:manufacturer_id/lines(.:format)          lines#index
                         POST   /manufacturers/:manufacturer_id/lines(.:format)          lines#create
   new_manufacturer_line GET    /manufacturers/:manufacturer_id/lines/new(.:format)      lines#new
  edit_manufacturer_line GET    /manufacturers/:manufacturer_id/lines/:id/edit(.:format) lines#edit
       manufacturer_line GET    /manufacturers/:manufacturer_id/lines/:id(.:format)      lines#show
                         PATCH  /manufacturers/:manufacturer_id/lines/:id(.:format)      lines#update
                         PUT    /manufacturers/:manufacturer_id/lines/:id(.:format)      lines#update
                         DELETE /manufacturers/:manufacturer_id/lines/:id(.:format)      lines#destroy
           manufacturers GET    /manufacturers(.:format)                                 manufacturers#index
                         POST   /manufacturers(.:format)                                 manufacturers#create
        new_manufacturer GET    /manufacturers/new(.:format)                             manufacturers#new
       edit_manufacturer GET    /manufacturers/:id/edit(.:format)                        manufacturers#edit
            manufacturer GET    /manufacturers/:id(.:format)                             manufacturers#show
                         PATCH  /manufacturers/:id(.:format)                             manufacturers#update
                         PUT    /manufacturers/:id(.:format)                             manufacturers#update
                         DELETE /manufacturers/:id(.:format)                             manufacturers#destroy
        new_user_session GET    /users/sign_in(.:format)                                 devise/sessions#new
            user_session POST   /users/sign_in(.:format)                                 devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)                                devise/sessions#destroy
           user_password POST   /users/password(.:format)                                devise/passwords#create
       new_user_password GET    /users/password/new(.:format)                            devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format)                           devise/passwords#edit
                         PATCH  /users/password(.:format)                                devise/passwords#update
                         PUT    /users/password(.:format)                                devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)                                  devise/registrations#cancel
       user_registration POST   /users(.:format)                                         devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)                                 devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)                                    devise/registrations#edit
                         PATCH  /users(.:format)                                         devise/registrations#update
                         PUT    /users(.:format)                                         devise/registrations#update
                         DELETE /users(.:format)                                         devise/registrations#destroy
                    root GET    /                                                        pages#home
                   about GET    /about(.:format)                                         pages#about
                         GET    /users/:id(.:format)                                     users#show
               all_users GET    /users(.:format)                                         users#index
          public_profile GET    /users/:name(.:format)                                   users#show

应用程序/视图/索引/ lines.html.erb

<h1>Listing lines</h1>
<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Manufacturer</th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>

  <tbody>
    <% @lines.each do |line| %>
      <tr>
        <td><%= line.name %></td>
        <td><%= line.manufacturer_id %></td>
        <td><%= link_to 'Show', manufacturer_lines_path(line.manufacturer, line) %></td>
        <td><%= link_to 'Edit', edit_manufacturer_line_path(line.manufacturer, line) %></td>
        <td><%= link_to 'Destroy', manufacturer_lines_path, method: :delete, data: { confirm: 'Are you sure?' } %></td>
      </tr>
    <% end %>
  </tbody>
</table>
<br>

1 个答案:

答案 0 :(得分:3)

使用单数line,而不是复数lines

manufacturer_line_path(line.manufacturer, line)

更新:

你的销毁链接看起来也很可疑 - 它应该与show动作的网址相同。