Alex Rivera | Logout

How do I get the absolute path of a resource in Rails 3?

Asked 2011-01-21T08:08:29.733
24

I would like to get the full absolute path to a resource including the domain name in Rails 3.

Example: to get the full path to the home page I have tried:

url_for( :controller => 'home', :action => 'index' )

and

root_path

but both give me just: / but I want: http://www.example.com/

The answer should also work on my dev server and return: http://localhost:3000/

Edit
Report

1 Answer

28

Ryan's answer is perfectly correct.

However, if you really needed to use url_for someday, just add :only_path => false to it's options and it'll make the url absolute for you. ;)

answered 2011-01-21T08:58:03.613

Your Answer