How do I make link_to open external URLs in a new window?

前端 未结 4 435
抹茶落季
抹茶落季 2021-01-30 14:39

I need to convert a rails 2.3 site so that all external URLs open in a new window. I could go though every call to link_to and add :target => \'_blank\'

4条回答
  •  梦毁少年i
    2021-01-30 15:29

    In rails 3.2+, it has been added as an option, just add

    = link_to 'facebook', 'http://www.facebook.com/fb-page', target: '_blank'
    

    and it'll open the link in a new tab.

提交回复
热议问题