在Ruby上按用户名链接到个人资料页面(Linking to profile page by username on Ruby)

编程入门 行业动态 更新时间:2024-10-15 20:17:23
在Ruby上按用户名链接到个人资料页面(Linking to profile page by username on Ruby)

我想要做的是当有人点击图片时他们会看到上传该图片用户名的用户,我希望他们能够点击该用户名并转到该人员个人资料页面。

这是我的问题,我让它为第一篇文章工作。 我有多个用户,帖子显示每个用户的正确用户名。 它链接完美。 但对于之后的任何帖子,它会引发错误,每个帖子的用户ID都会变高。

这是我的个人资料页面,因此帖子知道此用户发布了这些图片。 当我点击第一张图片和用户名时,它正确地将我带到了这里。

现在,当我点击第二张图片时,我得到了这个。 如果我点击第3张图片,我找不到“id”= 2的用户。 即使帖子通过拥有正确的用户名来识别谁发布了图片。

这是我在帖子中显示的代码

<div class="panel-body"> <p><strong><%= link_to(@post.user.username.capitalize, user_path) if @post.user %></strong></p> <p><%= @post.description %></p> <% if @post.user == current_user %> <%= link_to 'Edit', edit_post_path(@post) %> <% end %> </div>

再次,它适用于第一次上传如果你们需要看到更多的代码我会很乐意上传它

What I want to be able to do is when someone clicks on a picture they will see the user who uploaded that pictures username and I want them to be able to click that username and go to that persons profile page.

Here is my issue I have it working for the first post. I do have multiple users and the posts show the correct username for each one. It links perfectly fine. But for any post after that it throws up an error and the user id gets higher for each post.

This is my profile page so the posts know that this user posts these pics. And when I click the first picture and the username it correctly takes me to here.

Now when I click the 2nd picture I get this. And if I click the 3rd pic I get couldn't find user with "id"=2. Even though the post recognizes who posted the pic by having the correct username.

This is the code I have on my show for the posts

<div class="panel-body"> <p><strong><%= link_to(@post.user.username.capitalize, user_path) if @post.user %></strong></p> <p><%= @post.description %></p> <% if @post.user == current_user %> <%= link_to 'Edit', edit_post_path(@post) %> <% end %> </div>

Again it works perfectly fine for the 1st upload If you guys need to see more code I will gladly upload it

最满意答案

你能试试吗? ( user_path(@post.user.id) )

<p><strong><%= link_to(@post.user.username.capitalize, user_path(@post.user.id)) if @post.user %></strong></p>

Could you try this ? ( user_path(@post.user.id) )

<p><strong><%= link_to(@post.user.username.capitalize, user_path(@post.user.id)) if @post.user %></strong></p>

更多推荐

本文发布于:2023-08-05 22:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1440810.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上按   用户名   个人资料   页面   链接

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!