เปลี่ยนเส้นทาง 301 เมื่อเปลี่ยนชื่อรูทไม่ทำงาน

ฉันกำลังพยายามใช้การเปลี่ยนเส้นทาง 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' เป็น: เปลี่ยนเส้นทาง (เส้นทาง: '/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"

ฉันจะเปลี่ยนเส้นทางหน้าผลิตภัณฑ์ทั้งหมดไปยังผลิตภัณฑ์และไม่มีเส้นทางสำหรับผลิตภัณฑ์ได้อย่างไร


person franckandbeans    schedule 09.10.2020    source แหล่งที่มา


คำตอบ (1)


ฉันพบปัญหาแล้ว เนื่องจากลำดับเส้นทาง

get '/products', to: เปลี่ยนเส้นทาง (เส้นทาง: '/produits') และอื่น ๆ ที่ได้รับจะต้องอยู่หลังเส้นทางทรัพยากร

ออเดอร์ก็สำคัญ!

person franckandbeans    schedule 09.10.2020