带有 Subdomain-fu 的嵌套路由

发布于 2024-08-25 16:47:09 字数 387 浏览 7 评论 0原文

我的应用程序中有一些标准的嵌套路由,我想使用 subdomain-fu gem 实现子域。所以我目前正在这样做:

example.com/stores/name_of_store/products/name_of_product

并且我想这样做:

name_of_store.example.com/products/name_of_product

似乎已经有一些关于 subdomain-fu 灯塔门票中嵌套路由的 subdomain-fu 失败的讨论,但该灯塔项目不再公开,所以我无法审查他们得出的任何结论。

很高兴听到人们谈论您如何使用 subdomain-fu 实现嵌套路由。

谢谢!

I have some standard nested routes in my app, and I want to implement subdomains using the subdomain-fu gem. So I'm currently doing this:

example.com/stores/name_of_store/products/name_of_product

and I want to do this:

name_of_store.example.com/products/name_of_product

There seems to have been some discussion about the failings of subdomain-fu with regard to nested routes in the subdomain-fu lighthouse tickets, but that lighthouse project is no longer public, so I can't review whatever conclusions they reached.

It would be great to hear from people regarding how you've implemented nested routes with subdomain-fu.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琉璃梦幻 2024-09-01 16:47:09

您根本不需要嵌套路由来实现这一点。您可以只使用 subdomain_fu (或手动)来查找 current_store,然后使用基本的 ProductsController 将其查找范围限定为商店内的产品:

# ApplicationController
def current_store
  @current_store ||= Store.find_by_subdomain(request.host)
end
helper_method :current_store

# ProductsController
def index
  @products = current_store.products.all
end

You shouldn't need nested routes at all to accomplish that. You can just use subdomain_fu (or manually) to find the current_store, then a basic ProductsController that scopes its finds to products within a store:

# ApplicationController
def current_store
  @current_store ||= Store.find_by_subdomain(request.host)
end
helper_method :current_store

# ProductsController
def index
  @products = current_store.products.all
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文