How to get the server port in a Rails initializer

不羁的心 提交于 2019-12-10 19:28:45

问题


I have multiple instances of Rails servers and there is a need for each one of them to know its own listening port in environment.rb. request.port will work in the controllers but not in the context of the environment.rb. Is there a way? Thanks!


回答1:


You can get the running rails port using this code:

Rails::Server.new.options[:Port]

You can take a look at the options parser in the Rails documentation to see what hash parameters are available.



来源:https://stackoverflow.com/questions/9574129/how-to-get-the-server-port-in-a-rails-initializer

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