Externe Links mit Ruby on Rails

30.07.2010 00:07 Gregor Panek Ruby on Rails 11

Einen Externen Link in Rails zu erstellen sollte eigentlich kein Problem darstellen. Jedoch kann es in Frust ausarten wenn man zwei, im nachhinein recht simple Dinge nicht beachtet.

Externen Link erstellen

Genau mit diesem Problem hatte ich am Anfang auch zu kämpfen. Wie erstelle ich einen Externen Link auf eine andere Webseite? Einen einfachen Link der auf eine Interne Seite zeigt erstellt man üblicherweise so:

<%=link_to "Name des Links", root_path%>  </pre>

Das vorgehen bei einem Externen Link ist eigentlich genauso, nur das man zum einen eine Option (target) hinzufügen muss und zum anderen darauf achten das der externe Link mit http:// beginnt.

<%=link_to "Google", "http://www.google.de", :target => "_blank"%> 

Dadurch erhält man einen Link der Google in einem neuen Tab öffnet. Die möglichen Optionen für das Element Target können aus der HTML Syntax entnommen werden.

Vergisst man http:// vor der Url, so wird der Pfad zum Link einfach nur an die Url der aktuellen Seite hinzugefügt, was natürlich beim Aufruf zu einem Fehler führt, da die Seite nicht gefunden werden kann.

Zurück

11 Kommentare zu Externe Links mit Ruby on Rails

gravatar

moncler to buy online
05.11.2014 04:39:56

Hey there! Someone in my Myspace group shared this site with us so I came to check it out. I'm definitely enjoying the information. I'm bookmarking and will be tweeting this to my followers! Outstanding blog and wonderful design and style.


gravatar

Karine
29.06.2017 04:53:06

I think this is among the most vital information for me. And i'm glad reading your article. But wanna remark on some general things, The website style is perfect, the articles is really excellent : D. Good job, cheers


gravatar

Jared
08.10.2018 11:23:39

This is very fascinating, You are an excessively skilled blogger. I have joined your feed and sit up for looking for extra of your magnificent post. Additionally, I've shared your web site in my social networks


gravatar

Wilbur
10.10.2018 00:28:50

I am regular visitor, how are you everybody? This paragraph posted at this site is really pleasant.


gravatar

Sanora
11.10.2018 17:13:23

An intriguing discussion is worth comment. I do think that you should write more on this subject matter, it may not be a taboo matter but usually people do not discuss such issues. To the next! Kind regards!!


gravatar

Parthenia
12.10.2018 18:05:04

What's up to every one, the contents existing at this web page are really remarkable for people knowledge, well, keep up the good work fellows.


gravatar

Jonelle
15.10.2018 07:46:32

Are you looking to see and talk to some really sexy girls? These girls are super dirty and it doesn’t cost a single cent to talk to them. It’s wall to wall babes at this site. Just visit https://t.irtyc.com/cvezzegjk?aff_id=29696&offer_id=3664&bo=2779,2778,2777,2776,3391 and sign up for your free account. You’ll be talking to these total babes in a matter of no time flat!


gravatar

Kenton
20.10.2018 13:06:25

There’s been a lot of changes since I last left a comment about my site. I’m starting to add the new features that I’ve wanted to. I hope in the next few weeks that all of it will be up and running. It’s going to take time and I haven’t had much of it to dedicate to this project. I thank you all for visiting my site and I hope you have a great weekend!


gravatar

Phillipp
24.10.2018 14:22:18

There’s been a lot of changes since I last left a comment about my site. I’m starting to add the new features that I’ve wanted to. I hope in the next few weeks that all of it will be up and running. It’s going to take time and I haven’t had much of it to dedicate to this project. I thank you all for visiting my site and I hope you have a great weekend!


gravatar

Coy
28.10.2018 13:46:24

Watch this amazing video of Ronaldo saving the game http://corneey.com/wZLrVn This is why he’s one of the best football players to ever live!


gravatar

Alex
09.11.2018 11:25:37

Have you heard Ariana Grande perform Thank U live? If not, then you’ve definitely got to hear it. Give it a listen by clicking here http://kudoflow.com/4Emv This might just be her best song ever!

Kommentar abgeben