From ee63532d40c9e06d5b38e9a2e98e00fbbe084064 Mon Sep 17 00:00:00 2001 From: Bernerd Schaefer Date: Fri, 4 Sep 2015 12:23:29 -0700 Subject: `url_for` does not modify polymorphic options The `url_for` methods in `actionpack` and `actionview` now make a copy of the provided options before generating polymorphic paths or URLs. The bug in the previous behavior is most noticeable in a case like: url_options = [:new, :post, param: 'value'] if current_page?(url_options) css_class = "active" end link_to "New Post", url_options, class: css_class --- actionview/lib/action_view/routing_url_for.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'actionview/lib/action_view') diff --git a/actionview/lib/action_view/routing_url_for.rb b/actionview/lib/action_view/routing_url_for.rb index 20d6b9a64c..b4cbc80bd5 100644 --- a/actionview/lib/action_view/routing_url_for.rb +++ b/actionview/lib/action_view/routing_url_for.rb @@ -105,10 +105,11 @@ module ActionView when :back _back_url when Array + components = options.dup if _generate_paths_by_default - polymorphic_path(options, options.extract_options!) + polymorphic_path(components, components.extract_options!) else - polymorphic_url(options, options.extract_options!) + polymorphic_url(components, components.extract_options!) end else method = _generate_paths_by_default ? :path : :url -- cgit v1.2.3