This project is archived and is in readonly mode.
polymorphic routes should handle collections through Model Class
Reported by mamooth | September 22nd, 2008 @ 11:28 AM
The rails 2.1 PolymorphicRoutes module should handle collection's url through Model Class :
In actionpack/test/controller/polymorphic_routes_test.rb :
def test_with_a_class
expects(:articles_url).with()
polymorphic_url(Article)
end
def test_with_a_class_in_an_array
expects(:articles_url).with()
polymorphic_url([Article])
end
def test_with_a_class_and_a_namespace
expects(:admin_articles_url).with()
polymorphic_url([:admin, Article])
end
in module ActionController module PolymorphicRoutes
...
def polymorphic_url(record_or_hash_or_array, options = {})
...
inflection =
...
# adding
when record.is_a?(Class)
args.pop
:plural
# end adding => this allow a Class to be mapped to the collection
...
end
Comments and changes to this ticket
-
Pratik December 21st, 2008 @ 04:15 PM
- Tag changed from actionpack, polymorphic, routes to 2.1, actionpack, polymorphic, routes
Could you please upload a patch using git-format-patch ?
Thanks.
-
Yehuda Katz (wycats) December 24th, 2008 @ 08:15 AM
@mamooth is there any chance you could provide tests that represent the desired output, not just the fact that articles_url will be called. This will help us ensure that your desired behavior does not break through any upcoming refactoring.
-
Pratik February 24th, 2009 @ 04:12 PM
- State changed from new to incomplete
Will reopen when there's a patch.
Thanks.
-
Niklas Holmgren May 8th, 2009 @ 09:42 PM
- Tag changed from 2.1, actionpack, polymorphic, routes to 2.1, actionpack, patch, polymorphic, routes
Created a patch complete with tests. Think I got all possible cases nailed.
-
CancelProfileIsBroken August 6th, 2009 @ 02:32 PM
- State changed from incomplete to open
-
José Valim August 8th, 2009 @ 01:52 PM
- Tag changed from 2.1, actionpack, patch, polymorphic, routes to 2.1, actionpack, bugmash, patch, polymorphic, routes
-
Dan Pickett August 8th, 2009 @ 03:49 PM
+1 verified - I've attached an updated patch for 2-3 stable
We should probably document this a little more.
Also it could lead to some misleading behavior as it relates to STI models. Overall, though it could be very handy. Good idea
-
Dan Pickett August 8th, 2009 @ 04:03 PM
trying to upload the patch for some reason it didn't take the first time
-
Yehuda Katz (wycats) August 8th, 2009 @ 04:50 PM
"Also it could lead to some misleading behavior as it relates to STI models." Do you know of any existing behavior this could break? I'm a bit wary of handy features that break existing assumptions. I'm posting to the list for more feedback.
-
José Valim August 8th, 2009 @ 04:57 PM
@Yehuda,
He might be referring that the model SuperProject should have "/projects" as url, instead of "/super_projects" (which would be the default). Anyway, this problem already appears today and I already saw a ticket around here to solve the issue (although I don't think the solution should rely on polymorphic_url).
Thinking out loud here, maybe we should add to ActiveModel::Naming something like route?
-
Repository August 8th, 2009 @ 05:00 PM
- State changed from open to resolved
(from [c284412b149e03f46144ef566bcd6a16750961b1]) 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
http://github.com/rails/rails/commit/c284412b149e03f46144ef566bcd6a... -
Yehuda Katz (wycats) August 8th, 2009 @ 05:01 PM
- State changed from resolved to open
José: It's hard to add to naming, because the whole issue is that you can't calculate it (you have to try the subclass first and then the superclass). Maybe you're saying to cache it on naming for a given app? Again, this could get complicated in the case of multiple apps in the same process (not something you can do today, but worth keeping in mind). I think it makes more sense to cache on the router instance, which will always have one per application.
-
José Valim August 8th, 2009 @ 05:04 PM
@Yehuda, agreed. I also proposed a router based solution on #1231, which is also about polymorphic_url.
-
Pratik August 8th, 2009 @ 05:19 PM
- State changed from open to resolved
Feel free to reopen AFTER there are any known issues. STI problem is a separate issue.
-
CancelProfileIsBroken August 8th, 2009 @ 11:07 PM
- Tag changed from 2.1, actionpack, bugmash, patch, polymorphic, routes to 2.1, actionpack, patch, polymorphic, routes
- Milestone cleared.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 1089 polymorphic routes should handle collections through Model Class (from [c284412b149e03f46144ef566bcd6a16750961b1]) Polymor...