Get server address (rails server)

I have google map web application on rails.

google map needs API key that depends on server address.
ex) and need different API key

I have API key for several addresses in database [some key] [some key]
localhost:3000 [some key] [some key]

I want to select proper key based on server address when server start up

Now I am manually changing API keys everytime I need to do.

#1 Is there any way to get server address (rails server itself)?

#2 Can this work be done when server startup? not every session?

Thank you


Answering the question #1 you can achieve this using the request.env[
‘HTTP_HOST’ ] variable, that will return you a string with the hostname
and the listening port, something like ‘localhost:8080’.
For the second one, I guess you could create like some constants for
storing those keys of your needs, but you’re not being very clear so I
can not go further. Hope this can help you.