2017-06-24 61 views
0

我有一箇舊的wordpress woocommerce網站,我在rails中重建。重定向路線

顯然它有一個產品模型和產品控制器與路線。

該網站已準備好推出。

我唯一的問題是舊的鏈接去

www.mydomain.com/product/product-name 

我怎麼要麼重定向或更改我的

www.mydomain.com/products/product-name 

我的路線文件看起來像這樣

resources :products do 
    resource :like, only: [:create,:destroy], module: :products 
    resource :collect, only: [:create,:destroy], module: :products do 
     put :sort, on: :collection 
    end 
    member do 
     get :toggle_status 
    end 
    end 

回答

0

http://guides.rubyonrails.org/routing.html#redirection

獲取上述 '/產品/:名稱',到:重定向( '/產品/%{名}')

+0

這正是我所需要的,它提供了一種很好的方式來確保我所有的反向鏈接都能正常工作,並且我可以使用新的應用程序改進邏輯。 –

1

您可以檢查rails routing guide檢查第4.7節翻譯路徑

爲你的情況轉換路線

+0

謝謝你很多,我非常感謝這個答案,我喜歡rails的簡單性和文檔 –