From e17df19b86a2ad0ed8c5657ef046c3e82cf6d63b Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 6 Mar 2007 07:47:23 +0000 Subject: Allow array and hash query parameters. Array route parameters are converted/to/a/path as before. References #6765, #7462. Closes #7047. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6343 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/routing.rb | 37 +++++++++++------------------ 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 723aaada83..b44dc0f901 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -452,26 +452,18 @@ module ActionController # is given (as an array), only the keys indicated will be used to build # the query string. The query string will correctly build array parameter # values. - def build_query_string(hash, only_keys=nil) + def build_query_string(hash, only_keys = nil) elements = [] - only_keys ||= hash.keys - - only_keys.each do |key| - value = hash[key] or next - key = CGI.escape key.to_s - if value.class == Array - key << '[]' - else - value = [ value ] - end - value.each { |val| elements << "#{key}=#{CGI.escape(val.to_param.to_s)}" } - end - - query_string = "?#{elements.join("&")}" unless elements.empty? - query_string || "" + (only_keys || hash.keys).each do |key| + if value = hash[key] + elements << value.to_query(key) + end + end + + elements.empty? ? '' : "?#{elements.sort * '&'}" end - + # Write the real recognition implementation and then resend the message. def recognize(path, environment={}) write_recognition @@ -545,7 +537,7 @@ module ActionController end nil end - + end class Segment #:nodoc: @@ -669,7 +661,7 @@ module ActionController end def extract_value - "#{local_name} = hash[:#{key}] #{"|| #{default.inspect}" if default}" + "#{local_name} = hash[:#{key}] && hash[:#{key}].to_param #{"|| #{default.inspect}" if default}" end def value_check if default # Then we know it won't be nil @@ -1195,10 +1187,9 @@ module ActionController # # great fun, eh? - options_as_params = options[:controller] ? { :action => "index" } : {} - options.each do |k, value| - options_as_params[k] = value.to_param - end + options_as_params = options.clone + options_as_params[:action] ||= 'index' if options[:controller] + options_as_params[:action] = options_as_params[:action].to_s if options_as_params[:action] options_as_params end -- cgit v1.2.3