Skip to content
This repository has been archived by the owner on Jul 28, 2018. It is now read-only.

Commit

Permalink
Prefer using prepend instead of alias_method_chain when it is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Scholz committed Mar 26, 2015
1 parent 4e9acc3 commit a6175e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/turbolinks.rb
Expand Up @@ -45,7 +45,11 @@ def call_with_turbolinks(env)

ActiveSupport.on_load(:action_view) do
(ActionView::RoutingUrlFor rescue ActionView::Helpers::UrlHelper).module_eval do
include XHRUrlFor
if defined?(prepend) && Rails.version >= '4'
prepend XHRUrlFor
else
include LegacyXHRUrlFor
end
end
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/turbolinks/xhr_url_for.rb
Expand Up @@ -3,6 +3,14 @@ module Turbolinks
# option by using the X-XHR-Referer request header instead of the standard Referer
# request header.
module XHRUrlFor
def url_for(options = {})
options = (controller.request.headers["X-XHR-Referer"] || options) if options == :back
super
end
end

# TODO: Remove me when support for Ruby < 2 && Rails < 4 is dropped
module LegacyXHRUrlFor
def self.included(base)
base.alias_method_chain :url_for, :xhr_referer
end
Expand Down

0 comments on commit a6175e9

Please sign in to comment.