Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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/

like image 224
Tim Santeford Avatar asked Jan 21 '11 08:01

Tim Santeford


People also ask

How do you find the absolute path in Ruby?

Pass a string to File. expand_path to generate the path to that file or directory. Relative paths will reference your current working directory, and paths prepended with ~ will use the owner's home directory.

How do you tell if a path is an absolute path?

An absolute path always contains the root element and the complete directory list required to locate the file. For example, /home/sally/statusReport is an absolute path. All of the information needed to locate the file is contained in the path string.


1 Answers

Use root_url. The _url extension on the end gives the full URL, something like http://localhost:3000/projects/1/tickets/2.

like image 188
Ryan Bigg Avatar answered Sep 29 '22 09:09

Ryan Bigg