views:

27

answers:

2

I want the following urls for my UserController:

localhost/user/join
localhost/user/login
localhost/user/user_name (this can be any name in here, it should fire the 'profile' action)

Then within the /user/user_name_here/ folder I want:

/user/user_name/blah1/
/user/user_name/blah2/
/user/user_name/blah3/

It seems doing resources :user only creates things for index/show/get, so I'm confused as to how to do this other than creating so many match '/user/join' etc. lines in routes.

A: 

Yup - 'resources :user' is just scaffolding for the usual CRUD methods. If you want paths additional to those, you're going to have to create routes (it's the only way your app knows how to route a given URL to a given controller and method).

The friendly_id gem does something similar to what you're suggesting (though I believe it's monkey-patching the .find method on ActiveRecords classes rather than handling routing specifically).

arcwhite
+2  A: 
match "user/:user_name" => "users#show"

then /user/username will redirect to the User controller, call the show method, and pass the :user_name param

you could do the same to other actions that doesn't neet parameters,

match '/user/login' => "sessions#new"
match '/user/join' => "user#new"
vrsmn