# Modify root URL generated by \<%= link\_to %\>

**URL:** <https://www.ruby-forum.com/t/modify-root-url-generated-by-link-to/169720>\
**Category:** Rails\
**Created:** [June 7, 2009, 7:19pm UTC](https://www.ruby-forum.com/t/modify-root-url-generated-by-link-to/169720 "2009-06-07T19:19:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [June 7, 2009, 7:19pm UTC](https://www.ruby-forum.com/t/modify-root-url-generated-by-link-to/169720/1 "2009-06-07T19:19:15Z")

</div>

Is there a way to manually specify the root url that a \<%= link\_to %\>  
generates? So i can make an auto generated url that used to go to  
[mywebsite.myhost.com/comments](http://mywebsite.myhost.com/comments) be go to [example.com/comments](http://example.com/comments) ?

The reason, if you’re wondering is that I have hosting at a site and my  
domain forwarded and masked through go-daddy. This means when you go to  
[example.com](http://example.com) you are seeing content on [mywebsite.myhost.com](http://mywebsite.myhost.com) but the url  
shows up as [example.com](http://example.com). The problem comes when you click on a link for  
lets say comments, for whatever reason instead of showing  
[example.com/comments](http://example.com/comments) in the url it just shows [example.com](http://example.com). If you type  
[example.com/comments](http://example.com/comments) directly into the address bar though, everything  
works great you get the content you expect and the url you expect. So  
how can i make my \<%= link\_to %\>'s use [example.com](http://example.com) as the base url  
instead of [mywebsite.myhost.com](http://mywebsite.myhost.com)???

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [June 7, 2009, 10:54pm UTC](https://www.ruby-forum.com/t/modify-root-url-generated-by-link-to/169720/2 "2009-06-07T22:54:23Z")

</div>

I tried setting the default\_url\_options in my config/environments.rb  
like this:

config.action\_controller.default\_url\_options = { :host =\>  
‘[example.com](http://example.com)’}

but I get this error when i restart my server I get this error, is there  
another way to accomplish this taks?

/opt/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:530:in  
`send': undefined method `default\_url\_options=’ for  
ActionController::Base:Class (NoMethodError)  
from  
/opt/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:530:in  
`initialize_framework_settings' from /opt/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:529:in `each’  
from  
/opt/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:529:in  
`initialize_framework_settings' from /opt/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:526:in `each’  
from  
/opt/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:526:in  
`initialize_framework_settings' from /opt/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:154:in `process’  
from  
/opt/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:in  
`send' from /opt/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:in `run’  
… 27 levels…  
from  
/opt/local/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/commands/server.rb:49  
from  
/opt/local/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`gem_original_require' from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’  
from script/server:3

Ruby 1.8.6  
Rails 2.2.2

---

<div class="post-metadata">

**Author:** ![indigoi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/b3f665/32.png) [@indigoi](https://www.ruby-forum.com/u/indigoi)\
**Post date:** [June 9, 2009, 5:48pm UTC](https://www.ruby-forum.com/t/modify-root-url-generated-by-link-to/169720/3 "2009-06-09T17:48:19Z")

</div>

Still haven’t been able to figure this out. Instead i just changed the  
nameserver on go-daddy to point at my RoR host’s servers. So even though  
i can’t host the DNS on the same server, i can have the DNS point at my  
RoR host server. Learn something new every day!
