diff options
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 17 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/url_for.rb | 7 |
2 files changed, 13 insertions, 11 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 0e5bf46ee4..c4d87ea3d9 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -195,7 +195,7 @@ module ActionDispatch @module.module_eval <<-END_EVAL, __FILE__, __LINE__ + 1 remove_possible_method :#{selector} def #{selector}(*args) - if args.size == #{route.required_parts.size} && !args.last.is_a?(Hash) && _optimized_routes? + if args.size == #{route.required_parts.size} && !args.last.is_a?(Hash) && optimize_routes_generation? options = #{options.inspect}.merge!(url_options) options[:path] = "#{optimized_helper(route)}" ActionDispatch::Http::URL.url_for(options) @@ -216,14 +216,9 @@ module ActionDispatch helpers << selector end - # If we are generating a path helper and we don't have a *path segment. - # We can optimize the routes generation to a string interpolation if - # it meets the appropriated runtime conditions. - # - # TODO We are enabling this only for path helpers, remove the - # kind == :path and fix the failures to enable it for url as well. + # Clause check about when we need to generate an optimized helper. def optimize_helper?(kind, route) #:nodoc: - kind == :path && route.ast.grep(Journey::Nodes::Star).empty? + route.ast.grep(Journey::Nodes::Star).empty? && route.requirements.except(:controller, :action).empty? end # Generates the interpolation to be used in the optimized helper. @@ -364,7 +359,7 @@ module ActionDispatch # Rails.application.routes.url_helpers.url_for(args) @_routes = routes class << self - delegate :url_for, :to => '@_routes' + delegate :url_for, :optimize_routes_generation?, :to => '@_routes' end # Make named_routes available in the module singleton @@ -602,6 +597,10 @@ module ActionDispatch false end + def optimize_routes_generation? + !mounted? && default_url_options.empty? + end + def _generate_prefix(options = {}) nil end diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index 191a2cb995..94db36ce1f 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -102,6 +102,9 @@ module ActionDispatch super end + # Hook overriden in controller to add request information + # with `default_url_options`. Application logic should not + # go into url_options. def url_options default_url_options end @@ -152,9 +155,9 @@ module ActionDispatch protected - def _optimized_routes? + def optimize_routes_generation? return @_optimized_routes if defined?(@_optimized_routes) - @_optimized_routes = default_url_options.empty? && !_routes.mounted? && _routes.default_url_options.empty? + @_optimized_routes = _routes.optimize_routes_generation? && default_url_options.empty? end def _with_routes(routes) |