HAML and Ruby loop and UL not working

一世执手 提交于 2019-12-12 14:43:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!