How to get the subdomain value from a url?

后端 未结 9 2275
太阳男子
太阳男子 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:02

    A bit late to the party but here's what I used in older versions of rails.

    subdomain = request.subdomains.join('.')

    It should be backwards compatible in newer versions

提交回复
热议问题