HAML and Ruby loop and UL do not work

I am trying to get this simple list to work, but ul closes and does not include li elements in the loop. Am I missing an easy way to do this?

  %ul.nav.nav-tabs.nav-stacked
   - @courses.each do |c|
   %li
    = link_to "add", { :controller => "admin/relateds", :action => "edit", :id => c.id }, :confirm => "Are you sure?"
    = c.coursetitle
+3
source share
2 answers

%liindentation is required because it is inside the block do. Even if this is valid markup , this will save you some debugging time if you decide to use 2 or 4 spaces for indentation for better legibility, since one of them is very difficult to distinguish.

%ul.nav.nav-tabs.nav-stacked
  - @courses.each do |c|
    %li
      = link_to "add", { :controller => "admin/relateds", :action => "edit", :id => c.id }, :confirm => "Are you sure?"
      = c.coursetitle
+3
source

you need to set aside% li and what should be inside. Your loop is currently doing nothing.

+1
source

All Articles