Defining a default route for a subdomain within Ruby on Rails
I'm trying to setup a subdomain within my Rai开发者_开发问答ls 2.3.10 application, using SubdomainFu - trying to setup m.domainname.com The aspect that I'm struggling with is trying to define a default route for the subdomain that is different than the default route for the main application.
If this is my route namespace for my subdomain:
map.namespace :mobile, :path_prefix => '', :conditions => { :subdomain => 'm' } do |mobile|
map.connect '/', :controller => 'mobile/mobile'
end
and then a little further down in my routes file, I have my default route:
map.default '/', :controller => 'pages', :action => 'home'
The default route for the namespace is overriding the main default route. If I move the primary default route above the namespace, then it takes precedence.
Any suggestions on how to best structure the route file and define a default route for the subdomain?
Thanks!
The line map.connect '/'
within the namespace block is still using the main map
object, which means that the routes are matching as if the namespace block around it have disappeared (and so the first route that matches -- the mobile controller -- is being used.)
Changing it to mobile.connect '/' ...
(i.e use the mobile
block variable that you've created) should fix the error you're seeing.
精彩评论