I have a problem where on each users profile they have an edit button for a section called wishlist, my problem is that when the user tries to click on the edit button it returns an error saying it cannot find wishlist with id e.g. 34 which is the user.id not the wishlist.id. But from what I can understand from the code that is not what I have wrote.
My code is as followed here:
users/show.html.erb
<div class="post3">
<h1><%= t('.mwg')%></h1><br />
<div id = "table-2">
<table width="240" >
<tbody>
<% Wishlist.where(:user_id => @user).each do |wishlist| %>
<tr><td width="30"><b>1:</b></td><td><%= wishlist.number_1 %></td></tr>
<tr><td width="30"><b>2:</b></td><td><%= wishlist.number_2 %></td></tr>
<tr><td width="30"><b>3:</b></td><td><%= wishlist.number_3 %></td></tr>
<tr><td width="30"><b>4:</b></td><td><%= wishlist.number_4 %></td></tr>
<tr><td width="30"><b>5:</b></td><td><%= wishlist.number_5 %></td></tr>
</tbody>
</table>
</div>
<%if current_user %>
<% if current_user.id == wishlist.user_id %>
<div id="text3"><%= link_to t('.edit'), edit_wishlist_path(@wishlist) %></div><br />
<%end%>
<%end%>
<%end%>
No I tried changing the current_user.id == wishlist.user_id line to the following:
<% if current_user.id == @wishlist.user_id %>
But I get the error of undefined method user_id
If I click on the edit for the original code it tries to find a wishlist who’s id matches that of the user but I want it to find a user whos id matches the user_id column.
You need to call edit_wishlist_path(wishlist), not @wishlist.