How to get the subdomain value from a url?

后端 未结 9 2273
太阳男子
太阳男子 2020-12-09 02:15

how can I get the subdomain value in rails, is there a built-in way to do this?

e.g.

test123.example.com

I want the test123 part of

9条回答
  •  情深已故
    2020-12-09 03:13

    For anyone looking to get the subdomains on localhost using WEBrick:

    Put config.action_dispatch.tld_length = 0 into config/environments/development.rb and everything should work.

    Link to SO post here: Can I make Rails / WEBrick recognize entries in /etc/hosts as subdomains (instead of domains)?

    Link to Github post: https://github.com/rails/rails/issues/12438

提交回复
热议问题