aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2010-08-04 23:00:33 +0200
committerPiotr Sarnacki <drogus@gmail.com>2010-09-03 22:59:12 +0200
commit8fb9df535e9fcf4c117ffd3254027e0fe2425cb7 (patch)
tree85bd6505a51f5b676c000e694118cbb7f456d57c /actionpack/lib/action_dispatch/routing
parent8284fd38551c00c30cf89fa22d1afd503a08c516 (diff)
downloadrails-8fb9df535e9fcf4c117ffd3254027e0fe2425cb7.tar.gz
rails-8fb9df535e9fcf4c117ffd3254027e0fe2425cb7.tar.bz2
rails-8fb9df535e9fcf4c117ffd3254027e0fe2425cb7.zip
Modified polymorphic_url to check for model's namespace
This change allows using namespaced models with polymorphic_url, in the way that you would use them without namespace. Let's say that you have Blog::Post model in namespaced Engine. When you use polymorphic_path with Blog::Post instances, like in form_for(@post), it will look for blog_posts_path named url helper. As we are inside Blog::Engine, it's annoying to always use the prefix. With this commit, blog_ prefix will be removed and posts_path will be called.
Diffstat (limited to 'actionpack/lib/action_dispatch/routing')
-rw-r--r--actionpack/lib/action_dispatch/routing/polymorphic_routes.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
index 15ee7c8051..037b94b577 100644
--- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
+++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
@@ -111,6 +111,10 @@ 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