Haml / Ruby / Rails有条件地添加元素?

时间:2013-08-08 00:48:23

标签: ruby-on-rails ruby if-statement haml

我有这段代码:

- userlist.each do |member|
  = render :partial => 'projects/member_small', :locals => { :user => member }

我想每两次添加一个div元素do | member |发生。所以基本上每两次一次。我想要这个:

- userlist.each do |member|
  .row
    = render :partial => 'projects/member_small', :locals => { :user => member }

1 个答案:

答案 0 :(得分:6)

您可以将列表分成两组:

- userlist.each_slice(2) do |group|
  .row
    - group.each do |member|
      = render :partial => 'projects/member_small', :locals => { :user => member }