Как закончить, если заявление в Haml? - PullRequest
0 голосов
/ 08 июня 2018

Я хочу преобразовать этот код в Haml, но без «конца» вся таблица становится частью условия «else», а не только «tr».Как это сделать?

`

<% if line_item == @current_item %>
  <tr id="current_item">
<% else %>
  <tr>
<% end %>
    <td><%= line_item.quantity %>&times;</td>
    <td><%= line_item.product.title %></td>
    <td class="item_price"><%= number_to_currency(line_item.total_price) %></td>
  </tr>

`

1 Ответ

0 голосов
/ 24 июня 2018

Обычно лучше всего указывать только атрибут, а не весь тег в предложении if

%tr{id: line_item == @current_item ? 'current_item' : nil}
  %td #{line_item.quantity}&times;
  %td= line_item.product.title
  %td.item_price= number_to_currency(line_item.total_price)
...