Map URL “/users/id” to “/dashboard” in Rails 3?

﹥>﹥吖頭↗ 提交于 2020-01-03 05:14:14

问题


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

Thanks


回答1:


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 :-)




回答2:


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



回答3:


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




回答4:


did you try something like that:

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

and after login redirect to dashboard_path



来源:https://stackoverflow.com/questions/4291922/map-url-users-id-to-dashboard-in-rails-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!