【发布时间】:2016-01-28 05:34:43
【问题描述】:
请原谅我...我知道还有其他类似标题的帖子,但我没有看到我的问题所以...
我正在尝试创建一个 url mysite.com/myusername/profile,我想知道如何为此创建路由。目前,user#profile 的 URL 就是 mysite.com/user/profile,但我想让它更具体一些,比如说每个用户都有一个像 JohnnySmith 这样的用户名,URL 是 mysite.com/JohnnySmith/轮廓。我在想类似的事情
get "/#{current_user.username}", to: "user#profile", as: user_profile
但我知道这是不正确的。
我还应该提到,任何人都无法访问 mysite.com/JohnnySmith/profile.... 当前用户必须是 JohnnySmith。
有人可以帮忙吗?谢谢。
【问题讨论】:
-
你知道设计是如何工作的吗,current_user 变量总是包含登录的用户资源。使用您的试用代码详细说明您的问题
-
它被称为漂亮的 url 检查链接:github.com/norman/friendly_id 而这个 rails casts 视频:railscasts.com/episodes/314-pretty-urls-with-friendlyid
标签: ruby-on-rails devise routes url-routing