From 8ec2175aee93ecfd928de67c0a125bccc5e1c152 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 23 Aug 2010 14:02:05 +0200 Subject: Added more tests for polymorphic_url with namespaced models and implemented missing use cases --- .../lib/action_dispatch/routing/polymorphic_routes.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 037b94b577..517936bc96 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -111,10 +111,6 @@ module ActionDispatch args.last.kind_of?(Hash) ? args.last.merge!(url_options) : args << url_options end - if namespace = record.class.parents.detect { |n| n.respond_to?(:_railtie) } - named_route.sub!(/#{namespace._railtie.railtie_name}_/, '') - end - url_for _routes.url_helpers.__send__("hash_for_#{named_route}", *args) end @@ -159,7 +155,8 @@ module ActionDispatch if parent.is_a?(Symbol) || parent.is_a?(String) parent else - ActiveModel::Naming.plural(parent).singularize + str = ActiveModel::Naming.plural(parent).singularize + remove_namespace(str, parent) end end end @@ -168,6 +165,7 @@ module ActionDispatch route << record else route << ActiveModel::Naming.plural(record) + remove_namespace(route, record) route = [route.join("_").singularize] if inflection == :singular route << "index" if ActiveModel::Naming.uncountable?(record) && inflection == :plural end @@ -177,6 +175,13 @@ module ActionDispatch action_prefix(options) + route.join("_") end + def remove_namespace(string, parent) + if namespace = parent.class.parents.detect { |n| n.respond_to?(:_railtie) } + string.sub!(/#{namespace._railtie.railtie_name}_/, '') + end + string + end + def extract_record(record_or_hash_or_array) case record_or_hash_or_array when Array; record_or_hash_or_array.last -- cgit v1.2.3