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/
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.
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.
Use root_url
. The _url
extension on the end gives the full URL, something like http://localhost:3000/projects/1/tickets/2
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With