0

I already have a route to match /username for the users show page. However, when I add another action, for example: followers and following as below:

 resources :users, :only => [:show] do
    get :following, :followers
  end

I get the URL /users/username/following instead of /username/following.

How can I make all the /users/username URL's be matched as /username/etc.. ?

Here's my /username route:

match '/:id' => 'users#show', :constraints => { :id => /[a-zA-Z0-9\-_]*/ }, :as => "user_profile"

thank you.

Edit:

I have fixed this by adding

match '/:id/following' => 'users#show/following', :as => "user_following"
match '/:id/followed' => 'users#show/following', :as => "user_followers"

But I'm not sure if that's the best solution. What I'd really want is a default route that would match all /:id/:action to the appropriate action omitting the /users.

donald
  • 23,587
  • 42
  • 142
  • 223
  • Please check my answer in this question [Drawing routes using user name in Rails 3 w/ devise](http://stackoverflow.com/questions/4514533/drawing-routes-using-user-name-in-rails-3-w-devise) as I believe the two questions are identical. – Ryan Bigg Jan 09 '11 at 11:06
  • Ryan, I'm not sure if I understand your answer. Can you please elaborate it so I can understand how it works? Thanks. – donald Jan 09 '11 at 11:52

2 Answers2

0

I have fixed this by adding

match '/:id/following' => 'users#show/following', :as => "user_following"
match '/:id/followed' => 'users#show/following', :as => "user_followers"

But I'm not sure if that's the best solution. What I'd really want is a default route that would match all /:id/:action to the appropriate action omitting the /users.

donald
  • 23,587
  • 42
  • 142
  • 223
0

Near the bottom

match ':id/:action', :controller => :users
Kevin
  • 1
  • 1