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

fix rails 5 deprecations #679

Merged
merged 1 commit into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/turbolinks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ class Engine < ::Rails::Engine
ActiveSupport.on_load(:action_controller) do
ActionController::Base.class_eval do
include XHRHeaders, Cookies, XDomainBlocker, Redirection
before_filter :set_xhr_redirected_to, :set_request_method_cookie
after_filter :abort_xdomain_redirect
if respond_to?(:before_action)
before_action :set_xhr_redirected_to, :set_request_method_cookie
after_action :abort_xdomain_redirect
else
before_filter :set_xhr_redirected_to, :set_request_method_cookie
after_filter :abort_xdomain_redirect
end
end

ActionDispatch::Request.class_eval do
Expand All @@ -25,7 +30,11 @@ def referer

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 unless RUBY_VERSION =~ /^1\.8/
end
Expand Down
6 changes: 3 additions & 3 deletions lib/turbolinks/redirection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module Turbolinks
# will respond with a JavaScript call to Turbolinks.visit(url).
module Redirection
extend ActiveSupport::Concern

def redirect_via_turbolinks_to(url = {}, response_status = {})
redirect_to(url, response_status)

self.status = 200
self.response_body = "Turbolinks.visit('#{location}');"
response.content_type = Mime::JS
response.content_type = Mime[:js]
end
end
end
end
15 changes: 11 additions & 4 deletions lib/turbolinks/xhr_url_for.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
module Turbolinks
# Corrects the behavior of url_for (and link_to, which uses url_for) with the :back
# option by using the X-XHR-Referer request header instead of the standard Referer
# Corrects the behavior of url_for (and link_to, which uses url_for) with the :back
# option by using the X-XHR-Referer request header instead of the standard Referer
# request header.
module XHRUrlFor
module LegacyXHRUrlFor
def self.included(base)
base.alias_method_chain :url_for, :xhr_referer
end

def url_for_with_xhr_referer(options = {})
options = (controller.request.headers["X-XHR-Referer"] || options) if options == :back
url_for_without_xhr_referer options
end
end

module XHRUrlFor
def url_for(options = {})
options = (controller.request.headers["X-XHR-Referer"] || options) if options == :back
super options
end
end
end