2014-03-19 51 views
0

我現在正在使用一些嵌套資源 - 用戶有很多製造商,製造商有很多生產線。我可以通過輸入URL手動輸入行顯示視圖,因爲它看起來像/ manufacturer/37/lines/5。但是當我查看製造商/ 37 /行頁面時,我將鼠標懸停在各行的「顯示」鏈接上,它會嘗試在最後的URL中填入一段時間,當我點擊它時,無處可去。像/manufacturer/37/lines.5這似乎不是一個有效的URL。有人能幫助我嗎?Rails路由添加'。'嵌套資源顯示頁面?

的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 

耙路線

    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> 

回答

3

使用奇異line,不是複數lines

manufacturer_line_path(line.manufacturer, line) 

UPDATE:

你摧毀鏈接看起來腥以及 - 它應該是相同的URL作爲表演動作。

+0

非常感謝。我的摧毀鏈接似乎工作,但我會記住這一點,以防它開始給我的問題。 – momchenr