Reputation: 5953
In Rails, have a workorders table. Each workorder can have children workorders. I'm trying to create dropdown links to sibling workorders. I'm testing by looking at workorder.id = 30. It has a sibling workorder.id = 20. I don't want to display a link to the same workorder the user is looking at (30).
So I put in a test <% if child.id != @workorder %>
. But, the 30 link still displays. I added some logger code to see what's going on.
This is my code:
<li class="dropdown-header">Siblings Links</li>
<% Workorder.find(@workorder).parent.children.each do |child| %>
<%= logger.info 'LOOK HERE ' %>
<%= logger.info child.id %>
<%= logger.info @workorder %>
<% if child.id != @workorder %>
<li><%= link_to child.id_desc, tasks_index4_path(:workorder_id => child) %></li>
<% end %>
<% end %>
The log shows:
LOOK HERE
30
30
LOOK HERE
30
20
Yet the link_to for 30 shows up.
Thanks for the help!
Upvotes: 0
Views: 51
Reputation: 26193
@workorder
presumably is a Workorder
object. As such, in order to compare the @workorder
to the child.id
, you'll need to access the id
attribute on @workorder
in order to make the correct comparison:
<% if child.id != @workorder.id %>
Upvotes: 1