Generating fully qualified URL based on the server


I have a cron job running at pre-determined time. This cron job is a small Ruby script that loads the whole Rails environment and does some jobs. One of the job is to send a link to users. The link needs to be full qualified. Meaning, it should be something like The domain part in the URL is variable. The cron job could be running from dev or staging or production servers. How can I generate these URLs?

Named routes aren't allowed in this Ruby script. To get to routes I have to do something like: ::ActionController::Routing::Routes

But even with that I am not able to generate the link. I tried url_for(:controller => 'user', :action => 'activate) and that doesn't work either. Any ideas how I can do this?

At the moment I have hard-coded the domain part in the script file.

where do you get the fully hostname from?

if you open the rails environment in a simple ruby script, you wont'
have a hostname, you'll have to specify it yourself. the url_for()
method ought to give you the relative path on the hostname that you
need to get the rest of the URL.

Does this help?


Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
VIDEO #3 out NOW!