问题
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