2012-03-17 60 views
0

我有一個房地產網站,我想訂購每本出版物的網址。在URL中組合控制器名稱(導軌路線)

出版物控制器有這樣的關係:

TYPE_ID(住宅出售,住宅出租,等..) COUNTRY_ID(美國,意大利,阿根廷等) STATE_ID(紐約,羅馬,布宜諾斯艾利斯布宜諾斯艾利斯等)

每個發佈我想是這樣的路徑:

http://www.domain.com/publication/house-for-sale/usa/new-york/24-street-therestofaddress

存在任何方式routes.conf做到這一點?

我使用friendly_id寶石,我喜歡沒有靜態路線的作品。

非常感謝

+0

我用friendly_id寶石和我一樣沒有靜態路由的作品。 – jgiunta 2012-03-17 23:57:53

回答

0

您可以使用static segments

match 'publication/:type/:country/:state/:id' => 'publications#show' 

然後在你的控制器,你可以訪問所有這些參數。例如,考慮URL http://www.domain.com/publication/house-for-sale/usa/new-york/24-street-therestofaddress其作爲控制器動作會處理:

class PublicationController < ApplicationController 
    def show 
    params[:type]  # "house-for-sale" 
    params[:country] # "usa" 
    params[:state] # "new-york" 
    params[:id]  # 24 
    end 
end 
+0

謝謝本,我會試試!但我喜歡這是一條自動路線生成的! – jgiunta 2012-03-17 23:56:02

+0

我不認爲有一個自動嵌套的資源解決方案映射到你想要的網址。 – 2012-03-17 23:58:28