2010-11-02 47 views
16

我有這樣的行routes.rb中默認值:Rails的:如何使用範圍使用參數和使用途徑與PARAMS

scope "/:subdomain/" do 
    resource :order, :only => [:new, :create, :show, :update, :edit, :destroy] do 
    get :cancel, :on => :member 
    put :counter, :on => :member 
    end 
end 

再舉例來說,這是典型的網址:http://mydomain.com/some_subdomain/order/new。這個URL被映射到params [:subdomain] =「some_subdomain」的命令控制器的action new。我想使用命名路線new_order_url(:subdomain =>「some_subdomain」)。

但我想將http://mydomain.com/order/new映射到訂單控制器,action new和params [:subdomain] =「default」。我想使用命名路由new_order_url這樣的網址。

這樣做的最佳做法是什麼?

+2

一個建議,使用'資源:順序:除了=> [:指數]'代替':只' – jpemberthy 2010-11-02 22:43:26

回答