Is there a way to pull the host server information in Ruby on Rails?
Such as a command?
I have links linking back to my RoR web application, but my web
application can and will move back and forth between servers and instead
of constantly changing these links to accommodate the server, is there a
way to define or pull server information and insert it in front of the
link as a variable? Thanks.
You could inspect the 'request' object and see what's there.., but if it's just for links, you could look at the :only_path => false part of url_for.
But, why do you need absolute links?
-philip
Philip Hallstrom wrote:
You could inspect the 'request' object and see what's there.., but if
it's
just for links, you could look at the :only_path => false part of
url_for.
But, why do you need absolute links?
-philip
Can you elaborate on that?
Im using absolute links because I'm using action mailer. So I'm sending
an email out when an entry in a table is created. The links are in these
emails. So say I create an entry. I, and other people, then receive an
email with a link back to this entry. Right now the link is based on my
localhost, but if the web application were moved, it would refer to the
wrong host. Does that make sense?
Yep! That's a good reason to have full urls
I'd look at the request object as well :only_path => false
url_for(options = {}, *parameters_for_method_reference)
Returns a URL that has been rewritten according to the options hash and the defined Routes. (For doing a complete redirect, use redirect_to). A url_for is used to: A All keys given to url_for are forwarded to the Route module, save for the following:
* :anchor specifies the anchor name to be appended to the path. For example, url_for :controller => posts, :action => show, :id => 10, :anchor => comments will produce "/posts/show/10#comments".
* :only_path if true, returns the absolute URL (omitting the protocol, host name, and port)
* :trailing_slash if true, adds a trailing slash, as in "/archive/2005/". Note that this is currently not recommended since it breaks caching.
* :host overrides the default (current) host if provided
* :protocol overrides the default (current) protocol if provided