Skip to content

Instantly share code, notes, and snippets.

@vjt
Created December 9, 2009 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vjt/252496 to your computer and use it in GitHub Desktop.
Save vjt/252496 to your computer and use it in GitHub Desktop.
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