Forum: Ruby on Rails link_to an external url ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
oo00oo (Guest)
on 2006-01-03 14:14
(Received via mailing list)
Simple question. Is it possible to generate a link like

<a href="http://www.google.com" target="_blank" >google</a>

with the link_to function ?

Thanks
Jarkko L. (Guest)
on 2006-01-03 14:23
(Received via mailing list)
On 3.1.2006, at 14.13, oo00oo wrote:

> Simple question. Is it possible to generate a link like
>
> <a href="http://www.google.com" target="_blank" >google</a>
>
> with the link_to function ?

Yes:

"Itâ??s also possible to pass a string instead of an options hash to
get a link tag that just points without consideration. If nil is
passed as a name, the link itself will become the name." [1]

So, <%= link_to "google", "http://www.google.com" %> should do the job.

//jarkko

[1] http://api.rubyonrails.com/classes/ActionView/Helpers/
UrlHelper.html#M000332
oo00oo (Guest)
on 2006-01-03 14:40
(Received via mailing list)
_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
Jan P. (Guest)
on 2006-01-03 15:00
(Received via mailing list)
Hi, ooOOoo,

as many rails functions the link_to function takes parameters that are
not mandatory for the function as an optional hash. You might write
anything into
this hash. So the answer to your question of a list of possible
:properties would be 'endless'. See for example:

<%= link_to "google", "http://www.google.com" , { :foo => "bar" } %>
producing
<a href="http://www.google.com" foo="bar">google</a>

You might have a look at http://www.w3schools.com/tags/tag_a.asp for key
=> value - pairs that make 'sense'.

Regards
Jan
Nshbrown N. (Guest)
on 2006-01-03 15:24
(Received via mailing list)
So you know, target="_blank" is not valid XHTML. I recommend reading
about
using the rel="external" tag if you so desire to popup a new window.

Here is some sample JavaScript I have in my default JS library code I
use in
such a case to ensure XHTML compliancy:

function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        if (anchor.getAttribute("href") && anchor.getAttribute("rel") ==
"external") {
            anchor.target = "_blank";
        }
    }
}
window.onload = externalLinks;

You can find fill documentation for the url_for method at:
http://www.railsmanual.org/class/ActionController%...

In addition, there are 3 special options for the html_options parameter
with
link_to, outlined here:
http://www.railsmanual.org/module/ActionView%3A%3A...
h_link_to

Regards,
Nathaniel

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Nathaniel S. H. Brown                           http://nshb.net
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Nshbrown N. (Guest)
on 2006-01-03 15:27
(Received via mailing list)
:target is a HTML (although non XHTML compliant) tag. All other HTML
attributes are valid tags such as :onmouseover, :onclick, :class, :id,
etc
can be used. They are not documented as you should reference W3 for what
HTML tags are truly valid.

-Nb

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Nathaniel S. H. Brown                           http://nshb.net
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oo00oo (Guest)
on 2006-01-03 17:10
(Received via mailing list)
perhaps :popup => true without sizes options is more simple than js ?
Nshbrown N. (Guest)
on 2006-01-03 17:45
(Received via mailing list)
Popus tend to lack all the toolbars due to the nature of what a popup
is.
Unless you stack it with options to match the feature set across all
browsers natively you will find that the JavaScript below may be a more
viable option. Search engines do not appreciate popup links and have a
hard
time following them for indexing, so you might be better off using such
a
tactic as mentioned via the JavaScript rel="external" option.

-Nb

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Nathaniel S. H. Brown                           http://nshb.net
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This topic is locked and can not be replied to.