Results 1 to 3 of 3
Thread: REST, routing, and overriding
Feb 10, 2008, 17:19 #1
REST, routing, and overriding
So I'm moving towards REST for one of my older apps, but there's some legacy stuff that is making things a bit more difficult. For example, this URL:
(Where "posts" is the main thing we're dealing with, "topic" is broad, and "category" belongs_to "topic".) I still want to keep that URL structure even though I have three separate models here: Post, Topic, and Category. So instead of cramming everything into the Post model, I've gone with traditional RESTful means, except in separate models. For example:
# => sends a request to my Topic controller to list all posts with the given topic.
The problem is that /posts is restful:
And I can't simply re-route it like so:
map.connect '/posts/:topic', :controller => 'topics', :action => 'index'
...because, well, Rails just doesn't like it. Even though I have that new route added, it still looks for the RESTful route of posts and gives me an exception.
Any thoughts? I'm on edge Rails.
Feb 12, 2008, 05:14 #2
- Join Date
- Oct 2007
- 0 Post(s)
- 0 Thread(s)
You can use standard routes and RESTful routes at the same time, however order becomes important. Makes sure the map.connect comes BEFORE the map.resource.
The other thing is to make sure the reg ex is right to - it looks like you want something more like /posts/:topic/:category - it might even help to tell the router that :topic and :category are string.
Don't forget "rake routes" is your friend.
Feb 12, 2008, 15:26 #3
Yeah, I've hit on all of those aspects; my guess is that map.connect in incompatible if you're trying to override map.resources, regardless of order. It might be one of those setups where conventions don't seem to work. I might have to end up manually describing all of the RESTful routes of the posts controller with the exception of the few that I need to be slightly different.