From 741316dc7123e8cdd750642dff6f39257d0ddbec Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Mon, 18 Jul 2005 03:12:45 +0000 Subject: Fixed construction of get parameters for arrays git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1857 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/url_rewriter.rb | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'actionpack/lib/action_controller/url_rewriter.rb') diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index 8ae6f3e57b..546bd13eb7 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -31,31 +31,27 @@ module ActionController rewritten_url end - def rewrite_path(options) - options = options.symbolize_keys - options.update((options[:params] || {}).symbolize_keys) + def rewrite_path(original_options) + options = original_options.symbolize_keys + options.update(params.symbolize_keys) if (params = options[:params]) RESERVED_OPTIONS.each {|k| options.delete k} - path, extras = Routing::Routes.generate(options, @request) + path, extra_keys = Routing::Routes.generate(options, @request) # Warning: Routes will mutate and violate the options hash - if extras[:overwrite_params] - params_copy = @request.parameters.reject { |k,v| %w(controller action).include? k } - params_copy.update extras[:overwrite_params] - extras.delete(:overwrite_params) - extras.update(params_copy) - end - - path << build_query_string(extras) unless extras.empty? + path << build_query_string(original_options.symbolize_keys, extra_keys) unless extra_keys.empty? path end # Returns a query string with escaped keys and values from the passed hash. If the passed hash contains an "id" it'll # be added as a path element instead of a regular parameter pair. - def build_query_string(hash) + def build_query_string(hash, only_keys = nil) elements = [] query_string = "" + + only_keys ||= hash.keys - hash.each do |key, value| + only_keys.each do |key| + value = hash[key] key = CGI.escape key.to_s key << '[]' if value.class == Array value = [ value ] unless value.class == Array -- cgit v1.2.3