Topic: map.resources and addressing resources using attributes other than id
I'm new to this forum, and also pretty new to rails and I've got a question concerning good style of writing rails-specific code.
My small application (or rather only a beginning of it) has a User model. Each user can submit some content, and it should be visible on their page.
I'd like to make it RESTful, but have the visitor use simple and meningful links to get to what they want - so I thought it'd be nice to add a possibility to address some resources by their permalinks or names, like this:
The first solution that came to my mind was to find proper content in the controller just by names or permalinks passed in params[:id], and change all the links that point to a given resource from something like user_path(@user) to user_path(@user.login). But that seems ugly, as I'd be using :id all the time to pass name or a different attribute.
I know that for nested resources I can use :path_prefix => '/users/:user_login' to get user's login in params[:user_login] and have the code semantically ok, like this:
@user = User.find_by_login params[:user_login]
@articles = @user.articles
This approach, however, will not work if I want to make map.resources map the 'mike' part of "/users/mike" to anything other than params[:id], will it?
So then I thought about using a meaningful GET/POST/PUT/DELETE parameter name, hence, except of map.resources, creating routes by means of map.connect (then I'd be able to specify the name of the parameter passed to the controller), but consequently, I'd have to use user_path(:name => @user.name) to address a given user's page and let the visitor see nice-looking url.
After reading for a while I got to know that I should first make everything work RESTfully and then start playing with nice links, but that would require either modifying helper methods user_path, user_url and so on or changing each use of this helper in the code to somehow point to a "nice" address instead of numeric :id.
Which of the method would seem the best for you and, hopefully, is there any different "rails magick" I don't know about?
Or maybe I should only use map.connect and write my own helper methods that would return "/users/mike" if invoked with user_path(@user)? Then I could easily switch between addressing using ids and login names without the need to change the links in views, as the helper would take whichever attribute I want from the model...
Is the problem worth considering, or should I just stay with passing meaningful unique attribute in id parameter?
I hope it's not a question that has already been asked somewhere here - I couldn't find anything related.
Thanks in advance,