Sha256: 2f128fadb7a70c2b24bdbf39147ce8aa6860bc665dd0e54493a96e2bb4f2e391

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

module ActionController
  module UrlWriter
    def url_for_with_subdomains(options)
      unless SubdomainFu.needs_rewrite?(options[:subdomain], options[:host] || default_url_options[:host])
        options.delete(:subdomain)
      else
        options[:only_path] = false 
        options[:host] = SubdomainFu.rewrite_host_for_subdomains(options.delete(:subdomain), options[:host] || default_url_options[:host])
      end
      url_for_without_subdomains(options)
    end
    alias_method_chain :url_for, :subdomains
  end
  
  class UrlRewriter #:nodoc:
    private
    
    def rewrite_url_with_subdomains(options)
      unless SubdomainFu.needs_rewrite?(options[:subdomain], (options[:host] || @request.host_with_port))
        options.delete(:subdomain)
      else
        options[:only_path] = false
        options[:host] = SubdomainFu.rewrite_host_for_subdomains(options.delete(:subdomain), options[:host] || @request.host_with_port)
      end
      rewrite_url_without_subdomains(options)
    end
    alias_method_chain :rewrite_url, :subdomains
  end
  
  if Rails::VERSION::MAJOR >= 2 and Rails::VERSION::MINOR <= 1
    # hack for http://www.portallabs.com/blog/2008/10/22/fixing-subdomain_fu-with-named-routes/
    module Routing
      module Optimisation
        class PositionalArgumentsWithAdditionalParams
          def guard_condition_with_subdomains
            # don't allow optimisation if a subdomain is present - fixes a problem
            # with the subdomain appearing in the query instead of being rewritten
            # see http://mbleigh.lighthouseapp.com/projects/13148/tickets/8-improper-generated-urls-with-named-routes-for-a-singular-resource
            guard_condition_without_subdomains + " && !args.last.has_key?(:subdomain)"
          end

          alias_method_chain :guard_condition, :subdomains
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mbleigh-subdomain-fu-0.0.4 lib/subdomain_fu/url_rewriter.rb
mbleigh-subdomain-fu-0.0.5 lib/subdomain_fu/url_rewriter.rb