How can I have a single route map to different controllers
My current Rails 2 project has a couple of different resources, each of which needs to be accessible via root level permalinks (i.e. a user being accessible via http://domain.com/john and a group being accessible via http://domain.com/thehunters). I know in Rails 3 I could use a condition on the routes to have the permalinks route appropriately, however, routing conditions in Rails 2 are much more limited.
What's th开发者_开发问答e best way for me to make this work? The best I can come up with is having a PermalinkController that then calls on the correct actions in the correct controllers, but this ends up very unDRY, slow, and brittle.
This is a bad idea altogether. If anything, those two URLs should be http://domain.com/users/john
and http://domain.com/groups/thehunters
- at first glance, there is no difference between the two URLs you gave. thehunters
could just be another username. Try to be as RESTful as you can. URLs are important and should be easily understandable.
I think basically what you suggested is what needs to be done except for there is no reason to reroute to different controller. Your "Permalink"Controller should accept the variable from the params, interpret that variable to determine which model to use and in turn decide which view to use with that model and render that view.
精彩评论