# Displaying external url's

**URL:** <https://www.ruby-forum.com/t/displaying-external-urls/135209>\
**Category:** Rails\
**Created:** [April 19, 2008, 7:42am UTC](https://www.ruby-forum.com/t/displaying-external-urls/135209 "2008-04-19T07:42:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 19, 2008, 7:42am UTC](https://www.ruby-forum.com/t/displaying-external-urls/135209/1 "2008-04-19T07:42:16Z")

</div>

I am a rails beginner and I am having trouble displaying external urls  
on view.

This is what i have in DB for ex: [www.rubyonrails.com](http://www.rubyonrails.com), if i try to  
construct the url on the page using link\_to the url formed is -  
[http://localhost:3000/www.rubyonrails.com](http://localhost:3000/www.rubyonrails.com).

Can someone help me in fixing this issue.

Thanks

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 19, 2008, 8:05am UTC](https://www.ruby-forum.com/t/displaying-external-urls/135209/2 "2008-04-19T08:05:35Z")

</div>

\<%= link\_to @from\_DB.name\_url, “[http://www.rubyonrails.com](http://www.rubyonrails.com)”, {:target =\>  
“\_blank” } %\>

is it your solution?

Rgd,

Reinhart  
[http://teapoci.blogspot.com](http://teapoci.blogspot.com)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 19, 2008, 8:43am UTC](https://www.ruby-forum.com/t/displaying-external-urls/135209/3 "2008-04-19T08:43:44Z")

</div>

What do you want your url like ?

> [http://localhost:3000/www.rubyonrails.com](http://localhost:3000/www.rubyonrails.com)

IF YES, flow to here :

{RAILS\_ROOT}/config/route.rb

Add it :

map.web\_url ‘:url\_name’,  
:controller =\> ‘my\_controller’, :action =\> ‘my\_action’

in your view :

\<% @url\_list.each do |u| %\>  
\<%= link\_to u.url, :action=\>‘my\_action’, :url\_name =\> u.url %\>  
\<% end %\>

It will make your url in address bar to be  
[http://localhost:3000/www.rubyonrails.com](http://localhost:3000/www.rubyonrails.com)

BUT THE SCRIPT BELOW, for accessing external url with new windows.

> \<% @url\_list.each do |u| %\>  
> \<%= link\_to u.url, u.url, {:target=\>‘\_blank’} %\>  
> \<% end %\>

Reinhart  
[http://teapoci.blogspot.com](http://teapoci.blogspot.com)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 19, 2008, 8:28am UTC](https://www.ruby-forum.com/t/displaying-external-urls/135209/4 "2008-04-19T08:28:28Z")

</div>

I tried that, but still doesn’t work , the url formed is  
[http://localhost:3000/www.rubyonrails.com](http://localhost:3000/www.rubyonrails.com)  
This is what i have in the view

\<% @url\_list.each do |u| %\>  
\<%= link\_to u.url, “[www.rubyonrails.com](http://www.rubyonrails.com)”, {:target=\>‘\_blank’} %\>  
\<% end %\>

On Apr 19, 2:05 am, Visit Indonesia 2008 \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 19, 2008, 11:18am UTC](https://www.ruby-forum.com/t/displaying-external-urls/135209/5 "2008-04-19T11:18:52Z")

</div>

Hi there,

Try putting the http:// before the URL

MD
