Saya mencoba menerapkan pengalihan 301 di akar saya untuk menghapus halaman duplikat. Namun saya juga telah mengubah nama jalur root dari produk menjadi produk. Inilah rute saya:
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}')
dan inilah rute rel saya:
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
Masalahnya adalah saya telah mencoba mengubah get '/products', menjadi: redirect(path: '/produits') agar cocok tetapi itu memberi saya kesalahan berikut:
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"
Bagaimana cara mengarahkan semua halaman produk ke produk dan tidak memiliki rute untuk produk?