Allister
To do this, simply override to_param in your model. For instance:
#users.rb def to_param self.username end
You will soon encounter some problems:
- Conflicts with existing routes. For example, the username should not be "new", did it work?
- to select a user in the controller, you must create a method (what I did mayybe is not the best solution) in your model, for example, self.find_for_controller (username)
- your username should only contain characters with URL support (forget accents, conjunctions, etc.). The solution for this is to have a second attribute name
username_urlized , which, of course, must be unique and not contradict other routes.
And maybe more problems :)
Also, if you want something like twitter (yoursite.com/dynamicUserName), follow these steps in routes.rb:
resources :users, :path=>'' do
source share