SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    link_to and Target

    I cannot work out how to specify the target when using link_to to generate an anchor tag. I want to create a link that opens a second window (not a pop-up) and in html I would use something like:
    Code:
    <a href="www.sitepoint.com" target="_blank">Site Point</a>
    How can I specify a target with link_to?

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <%= link_to 'Site Point', {:action => 'foo'}, :target => '_blank' %>

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A great source to look up stuff like this is the Rails API documentation. Often times there are methods already declared which do what you wanted to do, such as this. The API is here:

    http://api.rubyonrails.com
    Happy switcher to OS X running on a MacBook Pro.

    Zend Certified Engineer

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that did it. I'd not tried the curly brackets before. I'd left them out which just resulted in a "?target=_blank" being appended to the end of the URL.

    I'd looked at:

    http://api.rubyonrails.com/classes/A...r.html#M000332

    but the only reference to a target is for pop-ups that I didn't want to use. However, the use of curly brackets is there! The solution is so obvious when you know it :-)

    Now, if api.rubyonrails allowed user input like that on the php.net pages, I could add a note.....

    Thank you both for your help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •