2014-03-19 53 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