简体   繁体   English

无需请求即可获取 Rails 应用程序域名

[英]Get Rails application domain name without request

Is there a way to get Rails` app domain name without use of the request?有没有办法在不使用请求的情况下获取 Rails 的应用程序域名?

I know how to get URL from the request, but what if there is no request and Rails is just running a delayed job task, can i get a domain name of the server where the Rails app is hosted?我知道如何从请求中获取 URL,但是如果没有请求并且 Rails 只是在运行延迟的作业任务,我可以获取托管 Rails 应用程序的服务器的域名吗?

There isn't a per se way of doing this due to how Rails is built but if it is a big enough project it might me stored somewhere.由于 Rails 的构建方式,本身并没有这样做的方法,但如果它是一个足够大的项目,我可能会将它存储在某个地方。

So you could look for a place where it is being set and use that elsewhere.因此,您可以寻找正在设置它的地方并在其他地方使用它。

For example, if the project uses request_store you could search for something like:例如,如果项目使用request_store ,您可以搜索以下内容:

RequestStore.store[:host] = SomeTable.stored_host_name

And use SomeTable.stored_host_name in your worker or migration or the place you want to use it which doesn't have a request at hand.并在您的工作人员或迁移或您想要使用它的地方使用SomeTable.stored_host_name ,但手头没有请求。

Have a great day!祝你有美好的一天!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM