问题
I'm trying to get this simple list working, but the ul is closing and not enclosing the li elements in the loop. Am I missing a simple 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
回答1:
The %li
needs indentation because it is within a do
block. Even if it is valid markup it will save you debugging time if you opt to use 2 or 4 spaces for indentation for better legibility, as one is very difficult to discern.
%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
回答2:
you need to indent the %li and what's supposed to be inside. Currently your loop does nothing.
来源:https://stackoverflow.com/questions/10192764/haml-and-ruby-loop-and-ul-not-working