-5

単純な HAML ループの実行方法。ERB ビューでは次のようになります。

<table>
<tr>
 <th></th>
 <th></th>
</tr>
 <%= @price. each do |row| %>
<tr>
 <td><%= row.year %></td>
</tr>
 <% end %>
</table>

例はこれを試しました:

%table
  %tbody
   %tr
    %th year
    %th price

エラー:

Inconsistent indentation: 3 spaces were used for indentation
4

1 に答える 1

2

endHAMLではインデントが重要であり、これはコードのネストを意味します。これにより、Rubyコードで終了タグとステートメントを使用できなくなります。HAMLにネストを正しく理解させるには、すべてのインデントが同じサイズである必要があります。たとえば、2つのスペースです。

したがって、ERBコードは次のようになります。

%table
  %tr
    %th
    %th
  - @price. each do |row|
    %tr
      %td= row.year
于 2013-01-29T09:53:31.227 に答える