This shows a table for open and closed tickets. The code for open tickets is identical with the closed tickets. I was trying to figure out a way to just write one code segment that will show both tables and use half of the code lines. With some changes I ended up to this code. With this code, if I iterate it twice and at at first use the word open and then rename it to closed then I will accomplish what I am after.I looked around and figured out that I need to use a dynamic variable name. Something like sum#{status}tickets (pretty sure that something like that doesn't work) where the status variable will be at the first iteration open and then closed at the second one.I was wondering if this is somehow possible (to iterate twice) and then dynamically set the variable's name.   <% if sumopentickets == 0 %>    <h3>Open Tickets</h3>    <h4>No open tickets.</h3>  <% else %>   <h3>Open Tickets</h3>  <table class=table>    <tr>      <th>Ticket Number</th>      <th>Title</th>      <th>Submitted by</th>      <th>Created at</th>      <th colspan=2>Status</th>    </tr>    <% @tickets.each do |ticket| %>    <% if ticket.status == open %>    <% user = User.find(ticket.user_id) %>     <tr>        <td><%= ticket.id %></td>        <td><%= link_to ticket.title, ticket_path(ticket.url_token) %></td>        <td><%= user.username %></td>        <td><%= ticket.created_at.strftime(%H:%M, %B %d, %Y) %></td>        <% if ticket.ticketmessages.last && ticket.ticketmessages.last.user_id %>        <td>(user waiting for reply...)</td>        <% end %>      </tr>    <% end %>    <% end %>  </table>  <% end %>  <% if sumclosedtickets == 0 %>    <h3>Closed Tickets</h3>    <h4>No closed tickets.</h3>  <% else %>  <h3>Closed Tickets</h3>  <table class=table>    <tr>      <th>Ticket Number</th>      <th>Title</th>      <th>Submitted by</th>      <th>Created at</th>      <th colspan=2>Status</th>    </tr>    <% @tickets.each do |ticket| %>    <% if ticket.status == closed %>      <% user = User.find(ticket.user_id) %>      <tr>        <td><%= ticket.id %></td>        <td><%= link_to ticket.title, ticket_path(ticket.url_token) %></td>        <td><%= user.username %></td>        <td><%= ticket.created_at.strftime(%H:%M, %B %d, %Y) %></td>        <% if ticket.ticketmessages.last && ticket.ticketmessages.last.user_id %>        <td>(user waiting for reply...)</td>        <% end %>      </tr>    <% end %>    <% end %>  </table>  <% end %>
Showing a table for open and closed tickets
ruby;ruby on rails