我已經根據以下定義了一條路線,但我收到了一些錯誤。下面是代碼概述所發生的事情紅寶石軌道多級路線路徑
namespace :shopping do
resources :merchants, only: [:index, :show] do
這一點我希望我將能夠使用= link_to shopping_merchant_path(merchant)
但是,這是給我下面的錯誤
No route matches {:action=>"show", :controller=>"shopping/merchants", :id=>nil, :locale=>#<Merchant id: 1, name: "52e9689bc89a", featured: false>} missing required keys: [:id]
耙路輸出
Pauls-Air% rake routes | grep shopping_merchant
shopping_merchant_products GET (/:locale)/shopping/merchants/:merchant_id/products(.:format) shopping/products#index {:locale=>/en/}
shopping_merchant_product GET (/:locale)/shopping/merchants/:merchant_id/products/:id(.:format) shopping/products#show {:locale=>/en/}
shopping_merchants GET (/:locale)/shopping/merchants(.:format) shopping/merchants#index {:locale=>/en/}
shopping_merchant GET (/:locale)/shopping/merchants/:id(.:format) shopping/merchants#show {:locale=>/en/}
它看起來像你缺少一個pa在您的視圖中將rameter指向'shopping_merchant_path',因爲您的商家正在作爲'locale'傳遞(這不是默認行爲 - 您是否安裝了某些區域設置gem?)「rake routes | grep shopping_merchant'? – omnikron
你是否需要設置params [:locale] –
你需要設置它,否則rails會採用:id爲:locale –