开发者

Nested routes with 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.

开发者_Go百科

Thanks!


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜