2015-12-16 49 views
0

我已經開發了使用摺疊引導的Ruby on Rails網頁。 與Haml我已經嘗試如下。 但也有一些意想不到的錯誤。使用HAML摺疊手風琴時出現意外錯誤

.accordion-group 
    .accordion-heading 
     %according-toggle{"data-toggle" => "collapse", "data-target"=>"#{heading}"} 
     = link_to heading, "#{heading}" 
    .accordion-body.collapse.in{:id => "#{heading}"} 
     .accordion-inner 
     -items.each do |item| 
     %li{ :class => (params[:controller] == item[:controller] ? "active" : "") } 
      = link_to item[:path] do 
      - if item[:data_icon] 
       %span{ :class => "nav-icon", :data => {"icon" => "#{item[:data_icon]}".html_safe}} 
       %span{ :class => "nav-text"} 
       = "#{item[:name]}" 
      - else 
       = "#{item[:name]}" 
+2

語法錯誤,意想不到的keyword_ensure,期待keyword_end ...:Util.html_safe(_erbout);保證; @haml_buffer = @haml_buffer .... 這是一個錯誤信息 –

回答

0

看來你的縮進不正確,你可以檢查以下items.each 線,應該是內循環。

.accordion-group 
    .accordion-heading 
    %according-toggle{"data-toggle" => "collapse", "data-target"=>"#{heading}"} 
     = link_to heading, "#{heading}" 
    .accordion-body.collapse.in{:id => "#{heading}"} 
    .accordion-inner 
     - items.each do |item| 
     %li{ :class => (params[:controller] == item[:controller] ? "active" : "") } 
      = link_to item[:path] do 
      - if item[:data_icon] 
       %span{ :class => "nav-icon", :data => {"icon" => "#{item[:data_icon]}".html_safe}} 
       %span{ :class => "nav-text"} 
       = "#{item[:name]}" 
      - else 
       = "#{item[:name]}" 
+0

你似乎是正確的,但我的問題與你的答案不同。 –

0

我改變了代碼如下。 原因是標題包含空格和特殊字符,如'&'。 所以我用下劃線替換它們。 之後,它正在工作。

.panel-group{:id=>"accordion"} 
    - groups.each do |heading, items| 
    .panel.panel-default 
    .panel-heading 
     %h4.panel-title 
     %a.accordion-toggle{"data-toggle" => "collapse", "data-parent"=>"#accordion",:href=>"#"+"#{heading}".gsub(/\W/,'_')} 
      = raw heading 
    .panel-collapse.collapse{:id=>"#{heading}".gsub(/\W/,'_')} 
     .panel-body 
     %ul.nav.nav-pills.nav-stacked 
      - items.each do |item| 
      %li{:class => (params[:controller] == item[:controller] ? "active" : "") } 
       = link_to item[:path] do 
       - if item[:data_icon] 
        %span{ :class => "nav-icon", :data => {"icon" => "#{item[:data_icon]}".html_safe}} 
        %span{ :class => "nav-text"} 
        = "#{item[:name]}" 
       - else 
        = "#{item[:name]}" 
+0

我已經這樣實現。 –