# Generating fully qualified URL based on the server

**URL:** <https://www.ruby-forum.com/t/generating-fully-qualified-url-based-on-the-server/134381>\
**Category:** Rails\
**Created:** [April 10, 2008, 11:47am UTC](https://www.ruby-forum.com/t/generating-fully-qualified-url-based-on-the-server/134381 "2008-04-10T11:47:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![subbu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@subbu](https://www.ruby-forum.com/u/subbu)\
**Post date:** [April 10, 2008, 11:47am UTC](https://www.ruby-forum.com/t/generating-fully-qualified-url-based-on-the-server/134381/1 "2008-04-10T11:47:05Z")

</div>

Hi,

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  
[http://ww.myapp.com/user/activate/asdfe234sv](http://ww.myapp.com/user/activate/asdfe234sv). 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.

---

<div class="post-metadata">

**Author:** ![subbu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@subbu](https://www.ruby-forum.com/u/subbu)\
**Post date:** [April 10, 2008, 12:10pm UTC](https://www.ruby-forum.com/t/generating-fully-qualified-url-based-on-the-server/134381/2 "2008-04-10T12:10:48Z")

</div>

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?

Julian.

Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)  
VIDEO #3 out NOW!  
[http://sensei.zenunit.com/](http://sensei.zenunit.com/)
