How to return current host or domain?

Hi,

Is there a simple function in Rails that will return the current host or domain?

Like if I was running on http://localhost:3000, is there a function that would return "localhost"?

And if I was on the live server, like http://apples.com, is there a function that would return "apples.com"?

Thanks for any help...................

Sorry to double post, but to clarify, I'm looking for a Ruby function that will do the same as Request.Url.Host

Triple post time. Many apologies to all offended parties.

In controllers and views, request.domain(2) will return the current host.

Unfortunately for me, request.domain does not work in rake tasks, so I am up the creek without a paddle.

That's normal: rake tasks are outside the request cycle, so they've no way of knowing how people access the site (ie localhost, a dotted ip address, one of the many domain names pointing at the server). Maybe you could explain what it is you are trying to do?

Fred

That's normal: rake tasks are outside the request cycle, so they've no way of knowing how people access the site (ie localhost, a dotted ip address, one of the many domain names pointing at the server). Maybe you could explain what it is you are trying to do?

Fred

I'm trying to send out an email from within the rake task, and I need to include a link in the email to a certain page on my site.

In development, I'd want the page to be "http://localhost:3000/fruits/my_fruit",

but in production, I'd want it to be "http://apples.com/fruits/my_fruit"

I'd rather not hard-code in the domain names, I'd like some way to just grab what domain I'm on and use that.

I think you're going to have to have some config file or whatnot. Just looking at my server it hosts half a dozen domains - there's no way it can guess which is the one you're interested in this time.

Fred

I think you're going to have to have some config file or whatnot. Just looking at my server it hosts half a dozen domains - there's no way it can guess which is the one you're interested in this time.

Fred

Yeah, I ended up putting the info in config files. Ah well, thanks for all the advice.