2016-09-14 92 views
0

我已經根據以下定義了一條路線,但我收到了一些錯誤。下面是代碼概述所發生的事情紅寶石軌道多級路線路徑

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/} 
+2

它看起來像你缺少一個pa在您的視圖中將rameter指向'shopping_merchant_path',因爲您的商家正在作爲'locale'傳遞(這不是默認行爲 - 您是否安裝了某些區域設置gem?)「rake routes | grep shopping_merchant'? – omnikron

+0

你是否需要設置params [:locale] –

+0

你需要設置它,否則rails會採用:id爲:locale –

回答

0

由於onikron建議您需要將參數傳遞給您的route

= link_to shopping_merchant_path(@merchant) 

我認爲你正試圖像

= link_to shopping_merchant_path(locale: @merchant) 

東西:區域=>#<商家ID:1,名稱: 「52e9689bc89a」,精選:假>

不需要:locale link_to

+0

:locale未被傳遞到link_to,因爲您可以從上面看到 –

+0

您可以將您的鏈接傳遞給代碼 –

+0

,因爲它的可疑導軌正在將'@ merchant'移動到' :locale' –