2

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!

MikeH
  • 866
  • 1
  • 14
  • 26

1 Answers1

2

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
bensie
  • 5,373
  • 1
  • 31
  • 34
  • Wow. I've been looking for a way to clean-up my white-labelled domains for ages. At first I read your answer and thought "wait, what does that have to do with anything" but I stared at it for 5 minutes and all of a sudden it made sense! There is no need to interpret the parent resource instance in routing time. It can be interpreted programmatically! Thank you!! – Amin Ariana Nov 22 '11 at 18:33