0.01
No commit activity in last 3 years
No release in over 3 years
ActionView helper to easily render external links.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
>= 0

Runtime

 Project Readme

Donate

external_link_to

This gem provides a wrapper around the built in ActionView::Helpers::UrlHelper#link_to method available in Rails. It creates a link tag with target="_blank" and rel="noopener noreferrer" attributes by default. Simple as that.

Installation

Add this line to your application's Gemfile:

gem 'external_link_to'

And then execute:

$ bundle

Usage

For instance, this link:

link_to 'Home', root_path, rel: 'noopener noreferrer', target: '_blank'
# => <a rel="noopener noreferrer" target="_blank" href="/">Home</a>Home

is exactly the same as:

external_link_to 'Home', root_path
# => <a rel="noopener noreferrer" target="_blank" href="/">Home</a>Home

Basicaly, if you want to open a link in a new tab, just replace link_to with external_link_to:

- link_to 'Home', root_path
+ external_link_to 'Home', root_path

Contributing

Do not hesitate to contribute to the project by adapting or adding features ! Bug reports or pull requests are welcome.

License

The gem is available as open source under the terms of the MIT License.