Several root to routes in rails 4.0

I'm trying to get rails to go to another controller action # according to subdomain, and this is what I still have in routes.rb

Petworkslabs::Application.routes.draw do

  get '/', to: 'custom#show', constraints: {subdomain: '/.+/'}, as: 'custom_root'
  get '/',  to: "welcome#home", as: 'default_root'
end

rake shows the correct routes I want to do

rake routes
      Prefix Verb   URI Pattern             Controller#Action
 custom_root GET    /                       custom#show {:subdomain=>"/.+/"}
default_root GET    /                       welcome#home

But for some reason I can’t get requests like abc.localhost: 3000 to get into the user controller. He always directs him to greet # at home. Any ideas? I am new to rails, so any general debugging tips would also be appreciated.

EDIT: I went through the code using a debugger, and this is what I found

(rdb: 32) request.domain "Abc.localhost" (rdb: 32) request.subdomain "" (rdb: 32) request.subdomain.present? Lying

, - , , . , , .

+4
3

- request.subdomain ( , , localhost, https://github.com/rails/rails/issues/12438). regex route.rb. ? , .

class Subdomain
  def self.matches?(request)

    request.domain.split('.').size>1 && request.subdomain != "www"
  end
end

route.rb

constraints(Subdomain) do
  get '/',  to: "custom#home", as: 'custom_root'
end

, .

EDIT: github https://github.com/rails/rails/issues/12438

+1

:

Rails 3 4:

get '/' => 'custom#show', :constraints => { :subdomain => /.+/ }
root :to => "welcome#home"
+5

@manishie , devo, localhost. , config/environments/development.rb:

config.action_dispatch.tld_length = 0

@manishie routes.rb:

get '/' => 'custom#show', :constraints => { :subdomain => /.+/ }
root :to => "welcome#home"

, tld_length 1, localhost , . pixeltrix : https://github.com/rails/rails/issues/12438

+1

All Articles