Я пытаюсь реализовать 301 редирект в своих корнях, чтобы удалить повторяющиеся страницы. Однако я также изменил имя корневого пути с продуктов на продукты. Вот мои маршруты:
resources :products, path: "produits" do
resources :product_variants, only: [:new, :create, :edit, :update]
collection do
get :unavailable_products
end
end
get '/products', to: redirect(path: '/produits')
get '/products/:id', to: redirect('/produits/%{id}')
а вот и мои рельсовые маршруты:
products GET /products(.:format) redirect(301, path: /produits)
GET /products/:id(.:format) redirect(301, /produits/%{id})
product_product_variants POST /produits/:product_id/product_variants(.:format) product_variants#create
new_product_product_variant GET /produits/:product_id/product_variants/new(.:format) product_variants#new
edit_product_product_variant GET /produits/:product_id/product_variants/:id/edit(.:format) product_variants#edit
product_product_variant PATCH /produits/:product_id/product_variants/:id(.:format) product_variants#update
PUT /produits/:product_id/product_variants/:id(.:format) product_variants#update
unavailable_products_products GET /produits/unavailable_products(.:format) products#unavailable_products
GET /produits(.:format) products#index
POST /produits(.:format) products#create
new_product GET /produits/new(.:format) products#new
edit_product GET /produits/:id/edit(.:format) products#edit
product GET /produits/:id(.:format) products#show
PATCH /produits/:id(.:format) products#update
PUT /produits/:id(.:format) products#update
DELETE /produits/:id(.:format) products#destroy
Проблема в том, что я попытался изменить get '/ products' на: redirect (path: '/ produits') для соответствия, но это дает мне следующую ошибку:
You should not use the `match` method in your router without specifying an HTTP method. If you want to expose your action to both GET and POST, add `via: [:get, :post]` option. If you want to expose your action to GET, use `get` in the router: Instead of: match "controller#action" Do: get "controller#action"
Как перенаправить все страницы продуктов на продукты и не иметь маршрута для продуктов?