0

How can I map the url /users/:id to /dashboard?

Thanks

donald
  • 23,587
  • 42
  • 142
  • 223

4 Answers4

2

Where is the id parameter with URL /dashboard? Or is this about the "current" user?

If these pages are about different users, one from parameter, the other from session. Then you actually need different controllers for these 2 URLs.

Here is how I would do it:

routes.rb

match "dashboard" => 'users#show', :defaults => { :id => -1 }

UsersController.rb

def show
  @user = User.find(params[:id] == -1 ? current_user_id : params[:id])
  ...

I let you do the implementation of current_user_id :-)

Vincent Robert
  • 35,564
  • 14
  • 82
  • 119
  • It is about the current_user. When I login, I want the URL to show /dashboard instead of /users/:id like it shows now. – donald Nov 27 '10 at 14:12
  • @donald: do you mean the login page should be served from `/dashboard`, or that the user should be redirected to `/dashboard` after logging in? – zetetic Nov 27 '10 at 20:09
  • @zetetic should be redirected to /dashboard once logged in. – donald Nov 27 '10 at 23:39
  • could you please explain better how that works? Shall I put that @user in all the methods in the controller? thanks. – donald Nov 27 '10 at 23:44
1
match "users/:id" => "YourDashboardController#dashboard"
Mahesh Velaga
  • 21,633
  • 5
  • 37
  • 59
0

Use this match "users/:id" => "YourDashboardController#dashboard"

hkairi
  • 385
  • 2
  • 9
0

did you try something like that:

match "/dashboard", :to => "users#show", :as => "dashboard"

and after login redirect to dashboard_path

Pasta
  • 1,750
  • 2
  • 14
  • 25