This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module YourApp | |
# This module fixes the double-port bug in generated URIs by an application | |
# running on a non-standard port (80 / 443). | |
# - vjt@openssl.it | |
# | |
# Ref: https://rails.lighthouseapp.com/projects/8994/tickets/1106-rewrite_url-adds-port-twice | |
# | |
module RewriterPatch | |
def self.included(rewriter) | |
rewriter.alias_method_chain(:rewrite, :double_port_fix) | |
end | |
def rewrite_with_double_port_fix(options = {}) | |
rewrite_without_double_port_fix(options).sub(/:\d+(:\d+\/?)/, '\1') | |
end | |
end | |
#unless ActionController::UrlRewriter.include? YourApp::RewriterPatch # DAMN | |
RW = ActionController::UrlRewriter | |
unless RW.instance_methods.include?('rewrite_with_double_port_fix') | |
class RW; include YourApp::RewriterPatch; end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment