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
<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 %>
Could you try this ? (
<p><strong><%= link_to(@post.user.username.capitalize, user_path(@post.user.id)) if @post.user %></strong></p>