Generating fully qualified URL based on the server

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. 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?

Julian.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs