HAML IF Indentation Problem

This is my code:

-@activities.each do |a|
  -if @i%3 == 0
    %ul
  %li=link_to a.name, a
  -@i += 1

I need li to be inside ul, which is inside the if statement. I cannot do this due to indentation. Can't I just point li to indent automatically?

thank

+3
source share
1 answer

I think you want to output a new% ul every time @i%3 == 0, and then put the tags %li. You can do the following:

-@activities.in_groups_of(3, false) do |activity_group|
  %ul
    -activity_group.each do |activity|
     %li=link_to activity.name, activity

To learn more about the topic, visit: http://railscasts.com/episodes/28-in-groups-of

Hope this helps.

+7
source

Source: https://habr.com/ru/post/1748315/


All Articles