1
我已成功集成了friendly-id并且工作正常。我的产品可以从(localhost:3000/product/test-product
)网址查看。我想要的是为我的产品设置一个简短的网址(localhost:3000/test-product
)。导轨中的友好id自定义网址
我该如何在friendly-id或rails中实现这一点。
预先感谢您。
我已成功集成了friendly-id并且工作正常。我的产品可以从(localhost:3000/product/test-product
)网址查看。我想要的是为我的产品设置一个简短的网址(localhost:3000/test-product
)。导轨中的友好id自定义网址
我该如何在friendly-id或rails中实现这一点。
预先感谢您。
您需要创建自定义的路线来实现这一点:
在routes.rb中
get ':id' => 'products#show', as: :product
呼叫像
product_path(product.slug)
感谢它为我工作。 :) – SujitS
这不适合我。我将它改为页面(而不是产品),尽管如此,URL仍然是/ pages/slug-value。我正在使用friendly_id 5.1来试试Rails 4.2。感到沮丧,因为它看起来应该很简单,但当我可以做一些其他重要的事情时,我花费了大量的时间: - / –