Accessing URL/URI information in Rails in the environments file?

孤街浪徒 提交于 2020-01-06 18:02:15

问题


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:


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.



来源:https://stackoverflow.com/questions/2931999/accessing-url-uri-information-in-rails-in-the-environments-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!