aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/polymorphic_routes.rb22
1 files changed, 18 insertions, 4 deletions
diff --git a/actionpack/lib/action_controller/polymorphic_routes.rb b/actionpack/lib/action_controller/polymorphic_routes.rb
index 18dc1bd72f..0e826d4ee7 100644
--- a/actionpack/lib/action_controller/polymorphic_routes.rb
+++ b/actionpack/lib/action_controller/polymorphic_routes.rb
@@ -3,6 +3,8 @@ module ActionController
def polymorphic_url(record_or_hash_or_array, options = {})
record = extract_record(record_or_hash_or_array)
+ namespace = extract_namespace(record_or_hash_or_array)
+
args = case record_or_hash_or_array
when Hash: [ record_or_hash_or_array ]
when Array: record_or_hash_or_array.dup
@@ -21,7 +23,7 @@ module ActionController
:singular
end
- named_route = build_named_route_call(record_or_hash_or_array, inflection, options)
+ named_route = build_named_route_call(record_or_hash_or_array, namespace, inflection, options)
send(named_route, *args)
end
@@ -51,8 +53,8 @@ module ActionController
"#{options[:routing_type] || "url"}"
end
- def build_named_route_call(records, inflection, options = {})
- records = Array.new([extract_record(records)]) unless records.is_a?(Array)
+ def build_named_route_call(records, namespace, inflection, options = {})
+ records = Array.new([extract_record(records)]) unless records.is_a?(Array)
base_segment = "#{RecordIdentifier.send("#{inflection}_class_name", records.pop)}_"
method_root = records.reverse.inject(base_segment) do |string, name|
@@ -60,7 +62,7 @@ module ActionController
segment << string
end
- action_prefix(options) + method_root + routing_type(options)
+ action_prefix(options) + namespace + method_root + routing_type(options)
end
def extract_record(record_or_hash_or_array)
@@ -70,5 +72,17 @@ module ActionController
else record_or_hash_or_array
end
end
+
+ def extract_namespace(record_or_hash_or_array)
+ returning "" do |namespace|
+ if record_or_hash_or_array.is_a?(Array)
+ record_or_hash_or_array.delete_if do |record_or_namespace|
+ if record_or_namespace.is_a?(String) || record_or_namespace.is_a?(Symbol)
+ namespace << "#{record_or_namespace.to_s}_"
+ end
+ end
+ end
+ end
+ end
end
end