Hi Paul,
This is a tricky problem that I've seen a couple of times in the Rails world, basically it boils down to the fact that the most your app can find out is the IP address and port that it binds to on the server. The external (internet facing) address might be different, there might be proxies, CDNs, DDOS protection and all sorts between your server and the user. Of course, there is a "Host" header in each HTTP request (which you can read off the Connection object in an action), but it could be different in multiple requests!
The way I've solved this is to have configs that define the `asset host` and the `base url` of your site and just use those (asset host is for images you want to include in your emails).
Hope that helps!