0

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

显然,它有一个 Product 模型和带路由的 Products 控制器。

该网站已准备好启动。

我唯一的问题是旧链接

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
4

2 回答 2

1

你可以检查rails routing guide check section 4.7 Translated Paths

对于您在翻译路线上方的情况

resources :products, path: 'product'
于 2017-06-24T08:50:53.510 回答
0

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

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

于 2017-06-24T08:55:33.773 回答