Topic: REST and Clean URLs

Hey Guys,

I am hoping to embark on my first rails development soon, I have got a very clear idea of what I want to do, and how I want the site to be structured.

One thing that is very important to me is getting a clear URL structure, with the theory that people could guess a URL, type it in and it would work. Flickr do this a lot, and it was explained in a talk I saw at FOWD.

So the sort of URLs I want to end up with are shown below, obviously there will be more of these as the site grows. (portal style page)

#Community … ead-title/ … tle/reply/ (reply permalink)

#Users (view users profile page)

So my question really is, is it possible to do these kinds of URLs onto a RESTful app?

I have been reading a lot about REST and understand the benefits of working in that way but am really not a fan of the URLs.

Thanks in advance for you help,


Re: REST and Clean URLs

IMO URLs shouldn't dictate the structure of the application. I recommend building the app RESTful to begin with, then customize the URLs later to your heart's content in the routes.

Railscasts - Free Ruby on Rails Screencasts

Re: REST and Clean URLs

Cheers for your reply Ryan,

I agree that the URLs should not dictate the structure of the app, the data can do that itself. Want I want to do is add this extra layer of "usability goodness" to the REST URLs.

What I wanted was clarification on if it is possible to "cloak" map.resources URLs with more user friendly ones.

Re: REST and Clean URLs

map.resources has some options to change its behavior (path_prefix for example) but it's not extremely flexible. For the most part, map.resources is just generating a bunch of named routes. What I recommend doing is, after you build the site RESTful, create custom named routes to suite your needs (you can leave map.resources at the bottom as a fallback if you want). Once you do this you may discover patterns which are specific to your project. You can extract these patterns into their own methods (similar to map.resources) to generate the custom routes for you so your routes file isn't hundreds of lines long.

Railscasts - Free Ruby on Rails Screencasts