簡體   English   中英

Rails路線添加“。” 嵌套資源顯示頁面?

[英]Rails Routes adding '.' to nested resource show page?

我現在正在使用一些嵌套資源-用戶有很多制造商,制造商有很多生產線。 我可以通過手動輸入URL來訪問線路顯示視圖,因為它看起來像/ manufacturer / 37 / lines / 5。 但是,當我查看制造商/ 37 /行頁面時,將鼠標懸停在單個行的“顯示”鏈接上時,它會嘗試在末尾的URL中填充一個句點,然后單擊它無處可去。 例如,/ manufacturer / 37 / lines.5,它似乎不是有效的網址。 有人可以幫我嗎?

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

app / views / index / 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>

使用單數line ,而不是復數lines

manufacturer_line_path(line.manufacturer, line)

更新:

您的銷毀鏈接看起來也很臟-它的網址應與show動作的網址相同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM