如何使用设计来查看个人资料页面
How to have viewable profile pages using devise
用户需要有自己的个人资料页面
另外,其他用户需要能够查看其他人的个人资料页面
我需要能够 link 在另一个 gem 中分析页面,例如我可以点击用户创建的 post(故事 gem) 并查看 post 读者的个人资料。
我找到了教程https://github.com/danweller18/devise/wiki/Allow-Users-to-View-Profile-and-List-All-Users
但这声称只允许用户查看自己的个人资料。我到底该怎么做(查看其他人的个人资料)
您可以查看其他人的个人资料,因为路由中有用户的 :id 参数。要 link 到用户的个人资料,请使用:
// using user's name as params
<%= link_to user_path(@user.name) %>
或者
// using user's id as params
<%= link_to user_path(@user) %>
嗯,
这是最常见的情况,在你的路线中你需要这样的东西
get user/:user_id/profile
然后在你看来你可以做类似的事情
if current_user.id == params[:user_id]
# your content when the user is the same
else
# content for others
此外,您可以尝试在控制器上执行此操作并呈现不同的内容
用户需要有自己的个人资料页面
另外,其他用户需要能够查看其他人的个人资料页面
我需要能够 link 在另一个 gem 中分析页面,例如我可以点击用户创建的 post(故事 gem) 并查看 post 读者的个人资料。
我找到了教程https://github.com/danweller18/devise/wiki/Allow-Users-to-View-Profile-and-List-All-Users
但这声称只允许用户查看自己的个人资料。我到底该怎么做(查看其他人的个人资料)
您可以查看其他人的个人资料,因为路由中有用户的 :id 参数。要 link 到用户的个人资料,请使用:
// using user's name as params
<%= link_to user_path(@user.name) %>
或者
// using user's id as params
<%= link_to user_path(@user) %>
嗯,
这是最常见的情况,在你的路线中你需要这样的东西
get user/:user_id/profile
然后在你看来你可以做类似的事情
if current_user.id == params[:user_id]
# your content when the user is the same
else
# content for others
此外,您可以尝试在控制器上执行此操作并呈现不同的内容