我已按照以下方式定义了一条路线,但我收到了一些错误。以下是概述正在发生的事情的代码
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]
rake路线输出
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/}
答案 0 :(得分:0)
正如onikron建议您需要将参数传递给route
= link_to shopping_merchant_path(@merchant)
我认为你正在尝试像
这样的东西= link_to shopping_merchant_path(locale: @merchant)
:区域设置=&GT;#&LT;商家ID:1,名称:&#34; 52e9689bc89a&#34;,特色:false&gt;
link_to
中无需:locale