From 36fd9efb5e4bfc9ac3acd4189d4dc457dea8102a Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Thu, 25 Feb 2010 15:05:10 -0800 Subject: Continued effort to deglobalize the router --- .../lib/action_dispatch/routing/route_set.rb | 23 ++++------------ actionpack/lib/action_dispatch/routing/url_for.rb | 31 +++++----------------- 2 files changed, 12 insertions(+), 42 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 8b761d393f..7bfe4fa2bf 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -194,24 +194,11 @@ module ActionDispatch # end @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1 def #{selector}(*args) - if args.empty? || Hash === args.first - options = #{hash_access_method}(args.first || {}) - else - options = #{hash_access_method}(args.extract_options!) - default = default_url_options(options) if self.respond_to?(:default_url_options, true) - options = (default ||= {}).merge(options) - - keys = #{route.segment_keys.inspect} - keys -= options.keys if args.size < keys.size - 1 # take format into account - - args = args.zip(keys).inject({}) do |h, (v, k)| - h[k] = v - h - end - - # Tell url_for to skip default_url_options - options[:use_defaults] = false - options.merge!(args) + options = #{hash_access_method}(args.extract_options!) + + if args.any? + options[:_positional_args] = args + options[:_positional_keys] = #{route.segment_keys.inspect} end url_for(options) diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index 64c695fe13..1d6da817ed 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -85,8 +85,6 @@ module ActionDispatch extend ActiveSupport::Concern included do - # ActionDispatch::Routing::Routes.install_helpers(self) - # Including in a class uses an inheritable hash. Modules get a plain hash. if respond_to?(:class_attribute) class_attribute :default_url_options @@ -97,23 +95,16 @@ module ActionDispatch self.default_url_options = {} end - # Overwrite to implement a number of default options that all url_for-based methods will use. The default options should come in - # the form of a hash, just like the one you would use for url_for directly. Example: - # - # def default_url_options(options) - # { :project => @project.active? ? @project.url_name : "unknown" } - # end - # - # As you can infer from the example, this is mostly useful for situations where you want to centralize dynamic decisions about the - # urls as they stem from the business domain. Please note that any individual url_for call can always override the defaults set - # by this method. def default_url_options(options = nil) - # ROUTES TODO: This should probably be an instance method self.class.default_url_options end - def rewrite_options(options) #:nodoc: - if options.delete(:use_defaults) != false && (defaults = default_url_options(options)) + def url_options + self.class.default_url_options.merge + end + + def merge_options(options) #:nodoc: + if options.delete(:use_defaults) != false && respond_to?(:default_url_options) && (defaults = default_url_options(options)) defaults.merge(options) else options @@ -149,19 +140,11 @@ module ActionDispatch when String options when Hash - _url_rewriter.rewrite(_router, rewrite_options(options)) + ActionController::UrlRewriter.rewrite(_router, merge_options(options)) else polymorphic_url(options) end end - - protected - - # ROUTES TODO: Figure out why _url_rewriter is sometimes the class and - # sometimes an instance. - def _url_rewriter - ActionController::UrlRewriter - end end end end \ No newline at end of file -- cgit v1.2.3