# Does the option :host work in link\_to?

**URL:** <https://www.ruby-forum.com/t/does-the-option-host-work-in-link-to/105278>\
**Category:** Rails\
**Created:** [May 28, 2007, 11:39am UTC](https://www.ruby-forum.com/t/does-the-option-host-work-in-link-to/105278 "2007-05-28T11:39:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shiwei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/53a042/32.png) [@Shiwei](https://www.ruby-forum.com/u/Shiwei)\
**Post date:** [May 28, 2007, 11:39am UTC](https://www.ruby-forum.com/t/does-the-option-host-work-in-link-to/105278/1 "2007-05-28T11:39:52Z")

</div>

Hi,

I used the following code line in a View file on machine  
[http://xx.test.com:7777](http://xx.test.com:7777):  
\<%= link\_to “GoToAnotherHost”, { :protocol =\> “http”, :host =\>  
“[app1books.test.com:7777](http://app1books.test.com:7777)”, :controller =\> “admin”, :action =\> “list” }  
%\>  
However the result is: the link “GoToAnotherHost” is always pointed to  
[http://xx.test.com:7777/admin/list](http://xx.test.com:7777/admin/list) rather than  
[http://app1books.test.com:7777/admin/list](http://app1books.test.com:7777/admin/list).  
I.e., the :host doesn’t take effect at all!  
What’s wrong with this? Do you meet the same problem?

Many Thanks!  
Shiwei

---

<div class="post-metadata">

**Author:** ![Shiwei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/53a042/32.png) [@Shiwei](https://www.ruby-forum.com/u/Shiwei)\
**Post date:** [May 28, 2007, 12:05pm UTC](https://www.ruby-forum.com/t/does-the-option-host-work-in-link-to/105278/2 "2007-05-28T12:05:54Z")

</div>

use :only\_path and the procotol like “http://” (see below) not what  
one would expect, but its mentioned in the manual.

```
<%= link_to "GoToAnotherHost",
{
  :only_path => false,
  :protocol => "http://",
  :host => "app1books.test.com:7777",
  :controller => "admin",
  :action => "list"
}
%>
```

---

<div class="post-metadata">

**Author:** ![Shiwei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/53a042/32.png) [@Shiwei](https://www.ruby-forum.com/u/Shiwei)\
**Post date:** [May 28, 2007, 5:08pm UTC](https://www.ruby-forum.com/t/does-the-option-host-work-in-link-to/105278/3 "2007-05-28T17:08:36Z")

</div>

You should be able to link\_to a string rather than a hash. Since  
routes vary from site to site the hash would be risky in any event.

Michael
