重定向路线

Redirect routes

我有一个在 rails 中重建的旧 wordpress woocommerce 网站。

显然它有一个产品模型和带有路由的产品控制器。

网站已准备好启动。

我唯一的问题是旧链接消失了

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

您可以查看 rails routing guide 查看第 4.7 节翻译路径

对于您在翻译路线上方的案例

resources :products, path: 'product'

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

获取'/product/:name',到:redirect('/products/%{name}')