Ruby on Rails route for wildcard subdomains to a controller/action

前端 未结 2 2012
暗喜
暗喜 2021-02-08 14:13

I dynamically create URLs of the form username.users.example.com:

bob.users.example.com
tim.users.example.com
scott.users.example.com
2条回答
  •  故里飘歌
    2021-02-08 15:03

    I think, you just need to do the following :

    create a class Subdomain in lib :

      class Subdomain  
        def self.matches?(request)  
          request.subdomain.present? && request.host.include?('.users')
        end  
      end
    

    and in your routes :

    constraints Subdomain do
      match '', to: 'my_controller#show'
    end
    

提交回复
热议问题