diff options
author | Niklas Holmgren <niklas.holmgren@mindset.se> | 2009-08-08 11:43:24 -0400 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-08-08 17:00:29 +0100 |
commit | c284412b149e03f46144ef566bcd6a16750961b1 (patch) | |
tree | 3e39cecdf7e7c8454051bd2c79ef7db39c2c6ba9 /actionpack/lib/action_controller | |
parent | ad98827a78d0ee13c5d3b8c5caf2fccfa294277c (diff) | |
download | rails-c284412b149e03f46144ef566bcd6a16750961b1.tar.gz rails-c284412b149e03f46144ef566bcd6a16750961b1.tar.bz2 rails-c284412b149e03f46144ef566bcd6a16750961b1.zip |
Polymorphic routes generates collection URL from model class [#1089 state:resolved]
Signed-off-by: Dan Pickett <dpickett@enlightsolutions.com>
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/routing/generation/polymorphic_routes.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/routing/generation/polymorphic_routes.rb b/actionpack/lib/action_controller/routing/generation/polymorphic_routes.rb index ee44160274..2adf3575a7 100644 --- a/actionpack/lib/action_controller/routing/generation/polymorphic_routes.rb +++ b/actionpack/lib/action_controller/routing/generation/polymorphic_routes.rb @@ -50,6 +50,7 @@ module ActionController # polymorphic_url([blog, post]) # => "http://example.com/blogs/1/posts/1" # polymorphic_url([:admin, blog, post]) # => "http://example.com/admin/blogs/1/posts/1" # polymorphic_url([user, :blog, post]) # => "http://example.com/users/1/blog/posts/1" + # polymorphic_url(Comment) # => "http://example.com/comments" # # ==== Options # @@ -70,6 +71,9 @@ module ActionController # record = Comment.new # polymorphic_url(record) # same as comments_url() # + # # the class of a record will also map to the collection + # polymorphic_url(Comment) # same as comments_url() + # def polymorphic_url(record_or_hash_or_array, options = {}) if record_or_hash_or_array.kind_of?(Array) record_or_hash_or_array = record_or_hash_or_array.compact @@ -93,6 +97,9 @@ module ActionController (record.respond_to?(:destroyed?) && record.destroyed?) args.pop :plural + elsif record.is_a?(Class) + args.pop + :plural else :singular end |