Angular compatible link_to. Turns
<%= link_to "Sign up", "/users/sign_up" %>
into
<a href="/users/sign_up" target="_self">Sign up</a>
| require "#{Rails.root}/lib/angular_helpers" |
| module ActionView | |
| module Helpers | |
| module UrlHelper | |
| def link_to_with_angular(name = nil, options = nil, html_options = nil, &block) | |
| if block_given? | |
| options = (options || {}).merge(target: "_self") | |
| else | |
| html_options = (html_options || {}).merge(target: "_self") | |
| end | |
| link_to_without_angular(name, options, html_options, &block) | |
| end | |
| alias_method_chain :link_to, :angular | |
| end | |
| end | |
| end |
| require 'action_view' | |
| require "./lib/angular_helpers" | |
| describe ActionView::Helpers::UrlHelper do | |
| include described_class | |
| it 'creates links with target _self' do | |
| expect(link_to('a','b')).to match /target="_self"/ | |
| end | |
| end |