aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-12-02 12:33:33 -0600
committerJoshua Peek <josh@joshpeek.com>2009-12-02 12:33:33 -0600
commit84be6cfb6452a23d5617cd8a8b200d8fb0431d5a (patch)
treed3ca3d22c006f9282cb8e7966d39a7fae6ac2fd0 /actionpack/lib
parentde40bc033a64c7074e01a8e8c585225f4cdaf81e (diff)
downloadrails-84be6cfb6452a23d5617cd8a8b200d8fb0431d5a.tar.gz
rails-84be6cfb6452a23d5617cd8a8b200d8fb0431d5a.tar.bz2
rails-84be6cfb6452a23d5617cd8a8b200d8fb0431d5a.zip
Fork rack build nested query to support to_param
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb45
1 files changed, 43 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index c2f6531a74..f029b634d6 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -379,7 +379,8 @@ module ActionDispatch
end
recall[:action] = options.delete(:action) if options[:action] == 'index'
- parameterize = lambda { |name, value|
+ opts = {}
+ opts[:parameterize] = lambda { |name, value|
if name == :controller
value
elsif value.is_a?(Array)
@@ -389,7 +390,22 @@ module ActionDispatch
end
}
- path = @set.url(named_route, options, recall, :parameterize => parameterize)
+ unless result = @set.generate(:path_info, named_route, options, recall, opts)
+ raise ActionController::RoutingError, "No route matches #{options.inspect}"
+ end
+
+ uri, params = result
+ params.each do |k, v|
+ if v
+ params[k] = v
+ else
+ params.delete(k)
+ end
+ end
+
+ uri << "?#{build_nested_query(params)}" if uri && params.any?
+ path = uri
+
if path && method == :generate_extras
uri = URI(path)
extras = uri.query ?
@@ -456,6 +472,31 @@ module ActionDispatch
def extract_request_environment(request)
{ :method => request.method }
end
+
+ private
+ def build_nested_query(value, prefix = nil)
+ case value
+ when Array
+ value.map { |v|
+ build_nested_query(v, "#{prefix}[]")
+ }.join("&")
+ when Hash
+ value.map { |k, v|
+ build_nested_query(v, prefix ? "#{prefix}[#{k}]" : k)
+ }.join("&")
+ when String
+ raise ArgumentError, "value must be a Hash" if prefix.nil?
+ "#{Rack::Utils.escape(prefix)}=#{Rack::Utils.escape(value)}"
+ when NilClass
+ Rack::Utils.escape(prefix)
+ else
+ if value.respond_to?(:to_param)
+ build_nested_query(value.to_param.to_s, prefix)
+ else
+ Rack::Utils.escape(prefix)
+ end
+ end
+ end
end
end
end