Hello, I have this cycle:
<% @session.number_of_session_places.times do |session| %> <% n = n+1 %> <div class="place_block" style=""><%= n %></div> <% @session.places.each do |p| %> <% if p.place_number == n %> <div class="place_block" style="background-color: black"><%= n %></div> <% end %> <% end %> <% end %>
For obvious reasons, he displays the block first.
<div class="place_block" style=""><%= n %></div>
And then
<div class="place_block" style="background-color: black"><%= n %></div>
With the same number. The remaining entries are displayed without duplicates. Tell me how to solve this problem, I can not logically think out a solution.
Logic : There is a session in the cinema (@session), and there is a number of seats in the hall (number_of_session_places). The first cycle displays for example 100 seats in the hall. Next, there is a table in the database (places) that is associated with the session table (that is, only reserved places are added to the (places) table, for example, 21 with an indication of the session id). It turns out that the second cycle goes through all the reserved places for this session and displays a block with a black background, if this place is booked. The logic is simple, if a place is reserved - a block with a standard background is displayed, otherwise - a block with a black background.