I have a routing question about rails 3, and setting up a conditional :root path.
Right now, my route.rb has the following:
root :to => "topics#index"
This is great and dandy, but only if a user is on their specific subdomain (basecamp style) on my site. If they go to www.myapp.com or myapp.com, this should not be the same :root. I was wonder if this was at all possible to setup, something that would be like...
if default_subdomain(www, "")
root :to => "promos#index"
else
root :to => "topics#index
end
I know this wouldn't be allowed in the routes.rb, but something that would do the same logical thing. Does anyone have any experience with this, or any documentation/blog that I could read over to try to set something like this up.
Thanks
Per chuck's help below(thanks a ton), this ended up being my working code:
constraints(:subdomain => "www") do
root :to => "promos#index"
end
root :to => "topics#index"
You can use the :requirements
tag to accomplish this.
root :to => "promos#index", :requirements => { :subdomain => "www" }
root :to => "topics#index"
I think this will work. I've never encountered it going by sub-domain/lack of a subdomain.
Edit: After doing some reading, Rails 3 uses :constraints
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With