Accessing URL/URI information in Rails in the envi

2019-09-20 06:18发布

How would I access the domain name from Rails inside the environments/deveopment.rb? I want to find out whether or not I am on localhost or a real domain. Thank you!

1条回答
地球回转人心会变
2楼-- · 2019-09-20 06:54

The environment files are not processed on every request- only at startup, so there wouldn't be any particular context at the time they are processed. This is really the job for a separate environment instead of having dev do double duty.

If you just want to check against the hostname or something though, you can do something like (assuming you're on a unix-like system):

my_host = `hostname`.chomp

and test against that, which may solve your problem.

查看更多
登录 后发表回答