How to get the subdomain value from a url?

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

    You can use the SubdomainFu plugin. This plugin gives you a method current_subdomain which returns the current_subdomain of your app.

    You can also have a look at this Railscast

    UPDATE

    You can also use request.subdomains this will give you an array of subdomains.

提交回复
热议问题