2011-11-04 48 views
2

我想,將以下網址:Rails中,路由映射不匹配正確的動作

/shop/{category_id}/{product_id}/ 

到所謂的「產品」

控制器動作我在路線已經得到了這一點:

match "/shop/:category/:id" => "shop#product" 

,我已經得到的link_to的如下:

link_to_unless_current "#{t('murals')}", url_for(:controller => 'shop', :category => 'walls', :id => 'murals') 

當URL被輸出,它們分別是:

http://0.0.0.0:3000/shop?category=walls&id=murals 

,而不是所期望的:

http://0.0.0.0:3000/shop/walls/murals 

如果切換路線,所以它去:

match "/shop/:category/:id" => "shop#index" 

這個作品,但這不是正確的行動。

任何幫助,將不勝感激。

+0

如果我硬編碼的URL,因此它設置爲: url_for(「/店/版畫,油畫/畫布」) 這將然後映射到產品的控制器和該網址顯示正常。所以,看起來問題是url_for的輸出而不是路由。有沒有辦法強制url_for使用適當的REST結構來覆蓋可怕的路徑輸出? –

回答

0

試試這個

<%= link_to_unless_current "#{t('murals')}", custom_path(:category => 'walls', :id => 'murals') %> 

match "/shop/:category/:id" => "shop#product", :as => :custom 
相關問題