映射 URL “/users/id"到“/仪表板"在 Rails 3 中? [英] Map URL "/users/id" to "/dashboard" in Rails 3?
本文介绍了映射 URL “/users/id"到“/仪表板"在 Rails 3 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将 url/users/:id 映射到/dashboard?
How can I map the url /users/:id to /dashboard?
谢谢
推荐答案
带有 URL /dashboard
的 id
参数在哪里?还是与当前"用户有关?
Where is the id
parameter with URL /dashboard
? Or is this about the "current" user?
如果这些页面是关于不同用户的,一个来自参数,另一个来自会话.那么你实际上需要为这 2 个 URL 使用不同的控制器.
If these pages are about different users, one from parameter, the other from session. Then you actually need different controllers for these 2 URLs.
我会这样做:
routes.rb
match "dashboard" => 'users#show', :defaults => { :id => -1 }
UsersController.rb
def show
@user = User.find(params[:id] == -1 ? current_user_id : params[:id])
...
我让你实现current_user_id
:-)
这篇关于映射 URL “/users/id"到“/仪表板"在 Rails 3 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文