Skip to content

Instantly share code, notes, and snippets.

@tomholford
Last active October 19, 2019 02:52
Show Gist options
  • Select an option

  • Save tomholford/5233c7148fa5ecb31fe921a79c475de1 to your computer and use it in GitHub Desktop.

Select an option

Save tomholford/5233c7148fa5ecb31fe921a79c475de1 to your computer and use it in GitHub Desktop.

Revisions

  1. tomholford revised this gist Oct 19, 2019. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions external_link_to.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,15 @@
    1. Add the following to `app/helpers/application_helper.rb`:
    ```ruby
    def external_link_to(name, path, **html_options)
    link_to name, path, { target: '_blank', rel: 'nofollow noopener' }.merge(html_options)
    def external_link_to(name = nil, options = nil, html_options = nil, &block)
    opts = { target: '_blank', rel: 'nofollow noopener' }
    if block_given?
    options ||= {}
    options = options.merge(opts)
    else
    html_options ||= {}
    html_options = html_options.merge(opts)
    end
    link_to(name, options, html_options, &block)
    end
    ```

  2. tomholford revised this gist Jun 25, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion external_link_to.md
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@
    <%= external_link_to 'Github', 'https://github.com/' %>
    ```

    Or with html options, like a class:
    Or, with html options like a class (also wrapping an image tag):
    ```erb
    <%= external_link_to image_tag('github.svg'), 'https://github.com/', class: 'icon-link' %>
    ```
  3. tomholford revised this gist Jun 25, 2019. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions external_link_to.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    1. Add the following to `app/helpers/application_helper.rb`:
    ```ruby
    def external_link_to(name, path)
    link_to name, path, target: '_blank', rel: 'nofollow noopener'
    def external_link_to(name, path, **html_options)
    link_to name, path, { target: '_blank', rel: 'nofollow noopener' }.merge(html_options)
    end
    ```

    @@ -10,5 +10,10 @@
    <%= external_link_to 'Github', 'https://github.com/' %>
    ```

    Or with html options, like a class:
    ```erb
    <%= external_link_to image_tag('github.svg'), 'https://github.com/', class: 'icon-link' %>
    ```

    More info on the extra link attributes here:
    https://developers.google.com/web/tools/lighthouse/audits/noopener
  4. tomholford renamed this gist Jun 25, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. tomholford created this gist Jun 25, 2019.
    14 changes: 14 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    1. Add the following to `app/helpers/application_helper.rb`:
    ```ruby
    def external_link_to(name, path)
    link_to name, path, target: '_blank', rel: 'nofollow noopener'
    end
    ```

    2. Use it like so in a view template:
    ```erb
    <%= external_link_to 'Github', 'https://github.com/' %>
    ```

    More info on the extra link attributes here:
    https://developers.google.com/web/tools/lighthouse/audits/noopener